blob: 6fa99241557d20737da0cbf71e53dd5fa8264bc3 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Christian Brabandtcb0c1132023-11-21 18:48:16 +00007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Travis Sheltone34d0e32024-07-30 21:08:56 +020023" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010024" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000025" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010026" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000027" Permission is hereby granted to use and distribute this code,
28" with or without modifications, provided that this copyright
29" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000030" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000031" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000032" expressed or implied. By using this plugin, you agree that
33" in no event will the copyright holder be liable for any damages
34" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010035"
36" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
37" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
38"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020039"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000040"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000041" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000042" (James 1:22 RSV)
43" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000044" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000045if &cp || exists("g:loaded_netrw")
46 finish
47endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020048
49" Check that vim has patches that netrw requires.
50" Patches needed for v7.4: 1557, and 213.
51" (netrw will benefit from vim's having patch#656, too)
52let s:needspatches=[1557,213]
53if exists("s:needspatches")
54 for ptch in s:needspatches
55 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
56 if !exists("s:needpatch{ptch}")
57 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
58 endif
59 let s:needpatch{ptch}= 1
60 finish
61 endif
62 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020063endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020064
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010065let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000066if !exists("s:NOTE")
67 let s:NOTE = 0
68 let s:WARNING = 1
69 let s:ERROR = 2
70endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000071
Bram Moolenaar1afcace2005-11-25 19:54:28 +000072let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010073setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020074"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010075"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010076"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000077
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000078" ======================
79" Netrw Variables: {{{1
80" ======================
81
Bram Moolenaar071d4272004-06-13 20:20:40 +000082" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020083" netrw#ErrorMsg: {{{2
84" 0=note = s:NOTE
85" 1=warning = s:WARNING
86" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010087" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
88" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
89" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010090" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020091fun! netrw#ErrorMsg(level,msg,errnum)
92" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
93
94 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020095" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020096 return
97 endif
98
99 if a:level == 1
100 let level= "**warning** (netrw) "
101 elseif a:level == 2
102 let level= "**error** (netrw) "
103 else
104 let level= "**note** (netrw) "
105 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100106" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200107
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200108 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
109 " use popup window
110 if type(a:msg) == 3
111 let msg = [level]+a:msg
112 else
113 let msg= level.a:msg
114 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200115 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200116 let s:popuperr_text= ""
117 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200118 " (default) netrw creates a one-line window to show error/warning
119 " messages (reliably displayed)
120
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100121 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200122 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100123" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124
125 " getting messages out reliably is just plain difficult!
126 " This attempt splits the current window, creating a one line window.
127 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100128" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100130" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100132 if type(a:msg) == 3
133 for msg in a:msg
134 NetrwKeepj call setline(line("$")+1,level.msg)
135 endfor
136 else
137 NetrwKeepj call setline(line("$")+1,level.a:msg)
138 endif
139 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100141" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 bo 1split
143 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200144 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100146 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100147" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200148 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100149 if type(a:msg) == 3
150 for msg in a:msg
151 NetrwKeepj call setline(line("$")+1,level.msg)
152 endfor
153 else
154 NetrwKeepj call setline(line("$"),level.a:msg)
155 endif
156 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100158" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200159 if &fo !~ '[ta]'
160 syn clear
161 syn match netrwMesgNote "^\*\*note\*\*"
162 syn match netrwMesgWarning "^\*\*warning\*\*"
163 syn match netrwMesgError "^\*\*error\*\*"
164 hi link netrwMesgWarning WarningMsg
165 hi link netrwMesgError Error
166 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100167" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200168 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200169
170 else
171 " (optional) netrw will show messages using echomsg. Even if the
172 " message doesn't appear, at least it'll be recallable via :messages
173" redraw!
174 if a:level == s:WARNING
175 echohl WarningMsg
176 elseif a:level == s:ERROR
177 echohl Error
178 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100179
180 if type(a:msg) == 3
181 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100182 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100183 endfor
184 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100185 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100186 endif
187
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100188" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200189 echohl None
190 endif
191
192" call Dret("netrw#ErrorMsg")
193endfun
194
195" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100196" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100197" Loosely, varname = value.
198fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100199" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200 if !exists(a:varname)
201 if type(a:value) == 0
202 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200203 elseif type(a:value) == 1 && a:value =~ '^[{[]'
204 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205 elseif type(a:value) == 1
206 exe "let ".a:varname."="."'".a:value."'"
207 else
208 exe "let ".a:varname."=".a:value
209 endif
210 endif
211endfun
212
213" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000214" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200215call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000216if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100217 call s:NetrwInit("s:THINLIST",0)
218 call s:NetrwInit("s:LONGLIST",1)
219 call s:NetrwInit("s:WIDELIST",2)
220 call s:NetrwInit("s:TREELIST",3)
221 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222endif
223
224" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200225" Default option values: {{{2
226let g:netrw_localcopycmdopt = ""
227let g:netrw_localcopydircmdopt = ""
228let g:netrw_localmkdiropt = ""
229let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200230
231" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000232" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200233if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
234 call s:NetrwInit("g:netrw_use_errorwindow",2)
235else
236 call s:NetrwInit("g:netrw_use_errorwindow",1)
237endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200238
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000239if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100240 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000241 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100242 elseif executable("curl")
243 let g:netrw_dav_cmd = "curl"
244 else
245 let g:netrw_dav_cmd = ""
246 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000248if !exists("g:netrw_fetch_cmd")
249 if executable("fetch")
250 let g:netrw_fetch_cmd = "fetch -o"
251 else
252 let g:netrw_fetch_cmd = ""
253 endif
254endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100255if !exists("g:netrw_file_cmd")
256 if executable("elinks")
257 call s:NetrwInit("g:netrw_file_cmd","elinks")
258 elseif executable("links")
259 call s:NetrwInit("g:netrw_file_cmd","links")
260 endif
261endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000262if !exists("g:netrw_ftp_cmd")
263 let g:netrw_ftp_cmd = "ftp"
264endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200265let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200266if !exists("g:netrw_ftp_options")
267 let g:netrw_ftp_options= "-i -n"
268endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000269if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100270 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100271 let g:netrw_http_cmd = "wget"
272 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100273 elseif executable("curl")
274 let g:netrw_http_cmd = "curl"
275 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200276 elseif executable("elinks")
277 let g:netrw_http_cmd = "elinks"
278 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000279 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100280 let g:netrw_http_cmd = "fetch"
281 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200282 elseif executable("links")
283 let g:netrw_http_cmd = "links"
284 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000285 else
286 let g:netrw_http_cmd = ""
287 endif
288endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100289call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100290call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100291call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
292call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200293call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200294if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200295 if executable("scp")
296 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
297 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200298 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200299 else
300 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
301 endif
302endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100303call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
304call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000305
Nir Lichtman1e34b952024-05-08 19:19:34 +0200306if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000307 \ && exists("g:netrw_use_nt_rcp")
308 \ && g:netrw_use_nt_rcp
309 \ && executable( $SystemRoot .'/system32/rcp.exe')
310 let s:netrw_has_nt_rcp = 1
311 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000312else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000313 let s:netrw_has_nt_rcp = 0
314 let s:netrw_rcpmode = ''
315endif
316
317" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000318" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000319" Cygwin Detection ------- {{{3
320if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200321 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
322 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000323 else
324 let g:netrw_cygwin= 0
325 endif
326endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000327" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_alto" , &sb)
329call s:NetrwInit("g:netrw_altv" , &spr)
330call s:NetrwInit("g:netrw_banner" , 1)
331call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200332call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100333call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200334call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100335call s:NetrwInit("g:netrw_compress" , "gzip")
336call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200337if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
338 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
339 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000340endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200341call s:NetrwInit("g:netrw_cursor" , 2)
342let s:netrw_usercul = &cursorline
343let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200344"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100345call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000346" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200347call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200348call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200349call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100350call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200351call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100352call s:NetrwInit("g:netrw_fastbrowse" , 1)
353call 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 +0000354if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000355 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
356 let g:netrw_ftp_list_cmd = "ls -lF"
357 let g:netrw_ftp_timelist_cmd = "ls -tlF"
358 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000359 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000360 let g:netrw_ftp_list_cmd = "dir"
361 let g:netrw_ftp_timelist_cmd = "dir"
362 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000363 endif
364endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100365call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000366" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100367call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000368if !exists("g:netrw_ignorenetrc")
369 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
370 let g:netrw_ignorenetrc= 1
371 else
372 let g:netrw_ignorenetrc= 0
373 endif
374endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100375call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000376if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000377 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100378 if exists("g:netrw_list_cmd_options")
379 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
380 else
381 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
382 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000383 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200384 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100385 if exists("g:netrw_list_cmd_options")
386 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
387 else
388 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
389 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000390 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100391" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000392 let g:netrw_list_cmd= ""
393 endif
394endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100395call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000396" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200397if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200398 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200399 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
400endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100401if !exists("g:netrw_localcmdshell")
402 let g:netrw_localcmdshell= ""
403endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000404if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200405 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000406 if g:netrw_cygwin
407 let g:netrw_localcopycmd= "cp"
408 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000409 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200410 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000411 endif
412 elseif has("unix") || has("macunix")
413 let g:netrw_localcopycmd= "cp"
414 else
415 let g:netrw_localcopycmd= ""
416 endif
417endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200419 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100420 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200421 let g:netrw_localcopydircmd = "cp"
422 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100423 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000424 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200425 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100426 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200427 elseif has("unix")
428 let g:netrw_localcopydircmd = "cp"
429 let g:netrw_localcopydircmdopt= " -R"
430 elseif has("macunix")
431 let g:netrw_localcopydircmd = "cp"
432 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200434 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100435 endif
436endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200437if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100438 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200439 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
440endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200441if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200442 if g:netrw_cygwin
443 call s:NetrwInit("g:netrw_localmkdir","mkdir")
444 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000445 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200446 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200447 endif
448else
449 call s:NetrwInit("g:netrw_localmkdir","mkdir")
450endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200451call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200452if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200453 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200454 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
455endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000456if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200457 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000458 if g:netrw_cygwin
459 let g:netrw_localmovecmd= "mv"
460 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000461 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200462 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000463 endif
464 elseif has("unix") || has("macunix")
465 let g:netrw_localmovecmd= "mv"
466 else
467 let g:netrw_localmovecmd= ""
468 endif
469endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100470" following serves as an example for how to insert a version&patch specific test
471"if v:version < 704 || (v:version == 704 && !has("patch1107"))
472"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100473call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
474" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000475if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000476 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000477endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000478if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000479 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
480endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000481" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100482call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
483call s:NetrwInit("g:netrw_maxfilenamelen", 32)
484call s:NetrwInit("g:netrw_menu" , 1)
485call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200486call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100487call s:NetrwInit("g:netrw_retmap" , 0)
488if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
489 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200490elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100491 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
492else
493 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000494endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100495call s:NetrwInit("g:netrw_preview" , 0)
496call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100497call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100498call s:NetrwInit("g:netrw_sshport" , "-p")
499call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
500call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
501call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100502call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
503" Default values - q-s ---------- {{{3
504call s:NetrwInit("g:netrw_quickhelp",0)
505let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100506 \ "(create new) %:file d:directory",
507 \ "(windows split&open) o:horz v:vert p:preview",
508 \ "i:style qf:file info O:obtain r:reverse",
509 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
510 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
511 \ "(history) qb:list u:go up U:go down",
512 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100513" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
514call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100515if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
516 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
517else
518 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
519endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
521call s:NetrwInit("g:netrw_sort_options" , "")
522call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000523if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200525 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526 else
527 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000528 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000529endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530call s:NetrwInit("g:netrw_special_syntax" , 0)
531call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200532call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100533call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100534call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000535" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200537if !exists("g:netrw_xstrlen")
538 if exists("g:Align_xstrlen")
539 let g:netrw_xstrlen= g:Align_xstrlen
540 elseif exists("g:drawit_xstrlen")
541 let g:netrw_xstrlen= g:drawit_xstrlen
542 elseif &enc == "latin1" || !has("multi_byte")
543 let g:netrw_xstrlen= 0
544 else
545 let g:netrw_xstrlen= 1
546 endif
547endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100548call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200549call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100550call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200551if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000552" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000553" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100554call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200555if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200556 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200557else
Bram Moolenaarff034192013-04-24 18:51:19 +0200558 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200559endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200560call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100561call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
562call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100563if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100564 let s:treedepthstring= "│ "
565else
566 let s:treedepthstring= "| "
567endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200568call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000569
570" BufEnter event ignored by decho when following variable is true
571" Has a side effect that doau BufReadPost doesn't work, so
572" files read by network transfer aren't appropriately highlighted.
573"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574
Bram Moolenaaradc21822011-04-01 18:03:16 +0200575" ======================
576" Netrw Initialization: {{{1
577" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200578if 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 +0100579" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100580 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200581" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100582 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100583 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
584 au VimEnter * let s:initbeval= &beval
585"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100586" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
587" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
588" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
589" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
590" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
591" 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 +0200592endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200593au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200594
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200595if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100596 com! -nargs=* NetrwKeepj keepj <args>
597else
598 let g:netrw_keepj= ""
599 com! -nargs=* NetrwKeepj <args>
600endif
601
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000602" ==============================
603" Netrw Utility Functions: {{{1
604" ==============================
605
Bram Moolenaaradc21822011-04-01 18:03:16 +0200606" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100607" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100608if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100609" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100610 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100611 if &ft != "netrw"
612 return ""
613 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200614 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
615 " popup error window is still showing
616 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
617 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
618 " text under mouse hasn't changed; only close window when it changes
619 call popup_close(s:popuperr_id)
620 unlet s:popuperr_text
621 else
622 let s:popuperr_text= v:beval_text
623 endif
624 let mesg= ""
625 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 +0100626 let mesg= ""
627 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
628 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
629 elseif getline(v:beval_lnum) =~ '^"\s*/'
630 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
631 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100632 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100633 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
634 let mesg = "S: edit sorting sequence"
635 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
636 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
637 elseif v:beval_text == "Quick" || v:beval_text == "Help"
638 let mesg = "Help: press <F1>"
639 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
640 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
641 else
642 let mesg= ""
643 endif
644 return mesg
645 endfun
646"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100647" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
648" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
649" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
650" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
651" 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 +0200652endif
653
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200655" netrw#Explore: launch the local browser in the directory of the current file {{{2
656" indx: == -1: Nexplore
657" == -2: Pexplore
658" == +: this is overloaded:
659" * If Nexplore/Pexplore is in use, then this refers to the
660" indx'th item in the w:netrw_explore_list[] of items which
661" matched the */pattern **/pattern *//pattern **//pattern
662" * If Hexplore or Vexplore, then this will override
663" g:netrw_winsize to specify the qty of rows or columns the
664" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100665" 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 +0200666" dosplit==1: the window will be split before running the local browser
667" style == 0: Explore style == 1: Explore!
668" == 2: Hexplore style == 3: Hexplore!
669" == 4: Vexplore style == 5: Vexplore!
670" == 6: Texplore
671fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100672" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%")." ft=".&ft)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100673" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200674 if !exists("b:netrw_curdir")
675 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100676" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200677 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100678
679 " record current file for Rexplore's benefit
680 if &ft != "netrw"
681 let w:netrw_rexfile= expand("%:p")
682 endif
683
684 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200685 let curdir = simplify(b:netrw_curdir)
686 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200687 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200688 let curdir= substitute(curdir,'\','/','g')
689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100690" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100691
692 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
693 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
694 " try Explore again.
695 if a:0 > 0
696" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100697 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
698 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
699 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
700 \ '~'.expand("<slnum>"))
701 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200702 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
703 if a1 != a:1
704 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
705 return
706 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100707 endif
708 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200709
710 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200711 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100712" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100713 sil! let keepregstar = @*
714 sil! let keepregplus = @+
715 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200716 sil! let keepregslash= @/
717
Bram Moolenaar8d043172014-01-23 14:24:41 +0100718 " if dosplit
719 " -or- file has been modified AND file not hidden when abandoned
720 " -or- Texplore used
721 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 call s:SaveWinVars()
723 let winsz= g:netrw_winsize
724 if a:indx > 0
725 let winsz= a:indx
726 endif
727
728 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200730 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200731 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200732
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200733 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200735 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200736 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200737
738 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200739 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200740 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200741 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200742
743 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200745 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200746 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200747
748 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200749 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200750 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200751 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200754 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200755 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200756 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200757
758 elseif a:style == 6 " Texplore
759 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 exe "keepalt tabnew ".fnameescape(curdir)
761 call s:RestoreBufVars()
762 endif
763 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200764 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100765 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
776 if dirname !~ '/$'
777 let dirname= dirname."/"
778 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200784 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 let dirname= a:1
791 endif
792 else
793 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 call s:NetrwClearExplore()
796" call Dret("netrw#Explore : cleared list")
797 return
798 endif
799
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 if dirname =~ '\.\./\=$'
802 let dirname= simplify(fnamemodify(dirname,':p:h'))
803 elseif dirname =~ '\.\.' || dirname == '.'
804 let dirname= simplify(fnamemodify(dirname,':p'))
805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100806" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200807
808 if dirname =~ '^\*//'
809 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
812 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
815
816 elseif dirname =~ '^\*\*//'
817 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 let pattern= substitute(dirname,'^\*\*//','','')
820 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822
823 elseif dirname =~ '/\*\*/'
824 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200827 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 let b:netrw_curdir = prefixdir
829 else
830 let b:netrw_curdir= getcwd().'/'.prefixdir
831 endif
832 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
833 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
835" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836
837 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200838 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100840" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200841
842 elseif dirname=~ '^\*\*/'
843 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
844 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100845" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200846
847 else
848 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100849" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850 endif
851
852 if starpat == 0 && a:indx >= 0
853 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 if dirname == ""
856 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100857" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200858 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200859 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200860 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200861 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200862 if dirname == ""
863 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200864 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100866 " depending on whether backslashes have been converted to forward slashes by earlier code).
867 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200868 let dirname= b:netrw_curdir."/".dirname
869 endif
870 elseif dirname !~ '^/'
871 let dirname= b:netrw_curdir."/".dirname
872 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100873" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100875" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
876" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 endif
878 if exists("w:netrw_bannercnt")
879 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
880 " If one wants to return the same place in the netrw window, use :Rex instead.
881 exe w:netrw_bannercnt
882 endif
883
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100884" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200885 " ---------------------------------------------------------------------
886 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
887" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100888" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200889" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100890" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200891" endif
892 " ---------------------------------------------------------------------
893
894 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
895 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
896 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
897 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
898 elseif a:indx <= 0
899 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100900" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200901 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100902" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200903 let s:didstarstar= 1
904 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
905 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
906 endif
907
908 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100909" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200910 if !exists("w:netrw_explore_indx")
911 let w:netrw_explore_indx= 0
912 endif
913
914 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200916
917 if indx == -1
918 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100919" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200920 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100921 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 +0200922 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100923" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100924 if @* != keepregstar | sil! let @* = keepregstar | endif
925 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100926 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200927 sil! let @/ = keepregslash
928" call Dret("netrw#Explore")
929 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 Moolenaara0f849e2015-10-30 14:37:44 +0100935" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
937 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100938" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200939 endwhile
940 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100941" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200942
943 elseif indx == -2
944 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100945" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100947 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 +0200948 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100949" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100950 if @* != keepregstar | sil! let @* = keepregstar | endif
951 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100952 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 sil! let @/ = keepregslash
954" call Dret("netrw#Explore")
955 return
956 endif
957 let indx= w:netrw_explore_indx
958 if indx < 0 | let indx= 0 | endif
959 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
960 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100961" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 while indx >= 0 && curfile == w:netrw_explore_list[indx]
963 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100964" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200965 endwhile
966 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100967" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200968
969 else
970 " Explore -- initialize
971 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100972" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100973 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 let w:netrw_explore_indx= 0
975 if !exists("b:netrw_curdir")
976 let b:netrw_curdir= getcwd()
977 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100978" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200979
980 " switch on starpat to build the w:netrw_explore_list of files
981 if starpat == 1
982 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
984" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200985 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100986 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200987 catch /^Vim\%((\a\+)\)\=:E480/
988 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
989" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
990 return
991 endtry
992 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
993 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
994
995 elseif starpat == 2
996 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100997" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
998" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001000 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 catch /^Vim\%((\a\+)\)\=:E480/
1002 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1003 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001004 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001005" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001006 if @* != keepregstar | sil! let @* = keepregstar | endif
1007 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001008 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 sil! let @/ = keepregslash
1010" call Dret("netrw#Explore : no files matched pattern")
1011 return
1012 endtry
1013 let s:netrw_curdir = b:netrw_curdir
1014 let w:netrw_explore_list = getqflist()
1015 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1016 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1017
1018 elseif starpat == 3
1019 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001020" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001021 let filepat= substitute(dirname,'^\*/','','')
1022 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001023" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1024" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001025 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1026 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1027
1028 elseif starpat == 4
1029 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001030" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001031 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1032 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1033 endif " switch on starpat to build w:netrw_explore_list
1034
1035 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1037" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001038
1039 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001040 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001041 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001042" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001043 if @* != keepregstar | sil! let @* = keepregstar | endif
1044 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001045 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001046 sil! let @/ = keepregslash
1047" call Dret("netrw#Explore : no files matched")
1048 return
1049 endif
1050 endif " if indx ... endif
1051
1052 " NetrwStatusLine support - for exploring support
1053 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001054" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001055
1056 " wrap the indx around, but issue a note
1057 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001058" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001059 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1060 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001061 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 endif
1063
1064 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001065" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001066 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001067" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001068
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001069" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 call netrw#LocalBrowseCheck(newdir)
1071 if !exists("w:netrw_liststyle")
1072 let w:netrw_liststyle= g:netrw_liststyle
1073 endif
1074 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001075 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001077 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 endif
1079 let w:netrw_explore_mtchcnt = indx + 1
1080 let w:netrw_explore_bufnr = bufnr("%")
1081 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001082 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084
1085 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001086" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001087 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 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 +02001089 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001090 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001091" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001092 if @* != keepregstar | sil! let @* = keepregstar | endif
1093 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001094 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001095 sil! let @/ = keepregslash
1096" call Dret("netrw#Explore : missing +path_extra")
1097 return
1098 endif
1099
1100 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001101" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001102 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1103 sil! unlet w:netrw_treedict
1104 sil! unlet w:netrw_treetop
1105 endif
1106 let newdir= dirname
1107 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001108 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001109 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001110 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001111 endif
1112 endif
1113
1114 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001115" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1116" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001117 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001118" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001119 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001120 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001121" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 let s:explore_prvdir = b:netrw_curdir
1123 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001124 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 if b:netrw_curdir !~ '/$'
1126 let dirlen= dirlen + 1
1127 endif
1128 let prvfname= ""
1129 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001130" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 if fname =~ '^'.b:netrw_curdir
1132 if s:explore_match == ""
1133 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1134 else
1135 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1136 endif
1137 elseif fname !~ '^/' && fname != prvfname
1138 if s:explore_match == ""
1139 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1140 else
1141 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1142 endif
1143 endif
1144 let prvfname= fname
1145 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001146" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001147 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1148 exe "2match netrwMarkFile /".s:explore_match."/"
1149 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001150 endif
1151 echo "<s-up>==Pexplore <s-down>==Nexplore"
1152 else
1153 2match none
1154 if exists("s:explore_match") | unlet s:explore_match | endif
1155 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001156" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001157 endif
1158
Bram Moolenaara6878372014-03-22 21:02:50 +01001159 " since Explore may be used to initialize netrw's browser,
1160 " there's no danger of a late FocusGained event on initialization.
1161 " Consequently, set s:netrw_events to 2.
1162 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001163 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001164" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001165 if @* != keepregstar | sil! let @* = keepregstar | endif
1166 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001167 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001168 sil! let @/ = keepregslash
1169" call Dret("netrw#Explore : @/<".@/.">")
1170endfun
1171
1172" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001173" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001174" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1175" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1176" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1177" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1178" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001179fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001180" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001181 let curwin= winnr()
1182
Bram Moolenaara6878372014-03-22 21:02:50 +01001183 if a:0 > 0 && a:1 != ""
1184 " if a netrw window is already on the left-side of the tab
1185 " and a directory has been specified, explore with that
1186 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001187" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001189" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001190 exe "1wincmd w"
1191 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001192" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193 exe "Explore ".fnameescape(a1)
1194 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001195 let s:lexplore_win= curwin
1196 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001198" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199 unlet t:netrw_lexposn
1200 endif
1201" call Dret("netrw#Lexplore")
1202 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001203 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 exe curwin."wincmd w"
1205 else
1206 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001207" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001208 endif
1209
Bram Moolenaar8d043172014-01-23 14:24:41 +01001210 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001212 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001213" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214 else
1215 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001216" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001218" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219
1220 if lexwinnr > 0
1221 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001222" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223 exe lexwinnr."wincmd w"
1224 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001225 let t:netrw_lexposn = winsaveview()
1226" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001227" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 close
1229 if lexwinnr < curwin
1230 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001231 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232 if lexwinnr != curwin
1233 exe curwin."wincmd w"
1234 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001235 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001236" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001237
1238 else
1239 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001240" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001241 exe "1wincmd w"
1242 let keep_altv = g:netrw_altv
1243 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001244 if a:count != 0
1245 let netrw_winsize = g:netrw_winsize
1246 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001248 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001249" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001250 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001251" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001252 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001253" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001254 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256 elseif curfile =~ '^\a\{3,}://'
1257" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001258 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001260" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001261 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 endif
1263 if a:count != 0
1264 let g:netrw_winsize = netrw_winsize
1265 endif
1266 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001267 let g:netrw_altv = keep_altv
1268 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001269 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1270 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001271 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001272 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001273" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1274" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001276" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001277" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1278 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001279 unlet t:netrw_lexposn
1280 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001281 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001282
1283 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001284 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001285 if a:rightside
1286 let g:netrw_chgwin= 1
1287 else
1288 let g:netrw_chgwin= 2
1289 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001290" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001291 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292
Bram Moolenaar8d043172014-01-23 14:24:41 +01001293" call Dret("netrw#Lexplore")
1294endfun
1295
1296" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001297" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001298" supports :NetrwClean -- remove netrw from first directory on runtimepath
1299" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001300fun! netrw#Clean(sys)
1301" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001302
1303 if a:sys
1304 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1305 else
1306 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1307 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001308" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001309 let diddel= 0
1310 let diddir= ""
1311
1312 if choice == 1
1313 for dir in split(&rtp,',')
1314 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001315" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001316 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1317 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1318 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1319 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1320 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1321 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 +00001322 let diddir= dir
1323 let diddel= diddel + 1
1324 if !a:sys|break|endif
1325 endif
1326 endfor
1327 endif
1328
1329 echohl WarningMsg
1330 if diddel == 0
1331 echomsg "netrw is either not installed or not removable"
1332 elseif diddel == 1
1333 echomsg "removed one copy of netrw from <".diddir.">"
1334 else
1335 echomsg "removed ".diddel." copies of netrw"
1336 endif
1337 echohl None
1338
Bram Moolenaara6878372014-03-22 21:02:50 +01001339" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001340endfun
1341
Bram Moolenaar5c736222010-01-06 20:54:52 +01001342" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001343" netrw#MakeTgt: make a target out of the directory name provided {{{2
1344fun! netrw#MakeTgt(dname)
1345" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1346 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001347 let svpos = winsaveview()
1348" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001349 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1350" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001351 if s:netrwmftgt_islocal
1352 let netrwmftgt= simplify(a:dname)
1353 else
1354 let netrwmftgt= a:dname
1355 endif
1356 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1357 " re-selected target, so just clear it
1358 unlet s:netrwmftgt s:netrwmftgt_islocal
1359 else
1360 let s:netrwmftgt= netrwmftgt
1361 endif
1362 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001363 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001364 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001365" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1366 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001367" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001368endfun
1369
Bram Moolenaara6878372014-03-22 21:02:50 +01001370" ---------------------------------------------------------------------
1371" netrw#Obtain: {{{2
1372" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001373" islocal=0 obtain from remote source
1374" =1 obtain from local source
1375" fname : a filename or a list of filenames
1376" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001377fun! netrw#Obtain(islocal,fname,...)
1378" 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 +02001379 " NetrwStatusLine support - for obtaining support
1380
1381 if type(a:fname) == 1
1382 let fnamelist= [ a:fname ]
1383 elseif type(a:fname) == 3
1384 let fnamelist= a:fname
1385 else
1386 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 +01001387" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001388 return
1389 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001390" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001391 if a:0 > 0
1392 let tgtdir= a:1
1393 else
1394 let tgtdir= getcwd()
1395 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001396" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001397
1398 if exists("b:netrw_islocal") && b:netrw_islocal
1399 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001400" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1402 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001403 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001407" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001408 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 if v:shell_error != 0
1410 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 +01001411" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 return
1413 endif
1414 endfor
1415 else
1416 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001417" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1418 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1419" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001420 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001421 if v:shell_error != 0
1422 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 +01001423" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 return
1425 endif
1426 endif
1427 elseif !exists("b:netrw_curdir")
1428 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1429 else
1430 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1431 endif
1432
1433 else
1434 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001435" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001436 if type(a:fname) == 1
1437 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1438 endif
1439 call s:NetrwMethod(b:netrw_curdir)
1440
1441 if b:netrw_method == 4
1442 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001443" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001444 if exists("g:netrw_port") && g:netrw_port != ""
1445 let useport= " ".g:netrw_scpport." ".g:netrw_port
1446 else
1447 let useport= ""
1448 endif
1449 if b:netrw_fname =~ '/'
1450 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1451 else
1452 let path= ""
1453 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001454 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001455 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 +02001456
1457 elseif b:netrw_method == 2
1458 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001460 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001461 let tmpbufnr= bufnr("%")
1462 setl ff=unix
1463 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001464 NetrwKeepj put =g:netrw_ftpmode
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("b:netrw_fname") && b:netrw_fname != ""
1469 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001471 endif
1472
1473 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001474 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001476 endif
1477 for fname in fnamelist
1478 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001479" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endfor
1481 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001482 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 +02001483 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endif
1486 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1487 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1488 let debugkeep= &debug
1489 setl debug=msg
1490 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1491 let &debug= debugkeep
1492 endif
1493
1494 elseif b:netrw_method == 3
1495 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001496" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001497 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001498 let tmpbufnr= bufnr("%")
1499 setl ff=unix
1500
1501 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001502 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001503" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001506" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001507 endif
1508
1509 if exists("g:netrw_uid") && g:netrw_uid != ""
1510 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001514 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 endif
1521 endif
1522
1523 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 endif
1527
1528 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001529 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001530" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endif
1532
1533 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537
1538 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001539 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001540" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001541 endif
1542 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001543 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001545" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001546
1547 " perform ftp:
1548 " -i : turns off interactive prompting from ftp
1549 " -n unix : DON'T use <.netrc>, even though it exists
1550 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001551 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1552 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001553 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001554 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1555 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001556" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001558 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001559 endif
1560 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001561
1562 elseif b:netrw_method == 9
1563 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001564" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001565 if a:fname =~ '/'
1566 let localfile= substitute(a:fname,'^.*/','','')
1567 else
1568 let localfile= a:fname
1569 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001570 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 +02001571
Bram Moolenaarff034192013-04-24 18:51:19 +02001572 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001573 " probably a badly formed url; protocol not recognized
1574" call Dret("netrw#Obtain : unsupported method")
1575 return
1576
1577 else
1578 " protocol recognized but not supported for Obtain (yet?)
1579 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001580 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001581 endif
1582" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001583 return
1584 endif
1585
1586 " restore status line
1587 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001588 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001589 endif
1590
1591 endif
1592
1593 " cleanup
1594 if exists("tmpbufnr")
1595 if bufnr("%") != tmpbufnr
1596 exe tmpbufnr."bw!"
1597 else
1598 q!
1599 endif
1600 endif
1601
Bram Moolenaara6878372014-03-22 21:02:50 +01001602" call Dret("netrw#Obtain")
1603endfun
1604
1605" ---------------------------------------------------------------------
1606" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1607fun! netrw#Nread(mode,fname)
1608" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001609 let svpos= winsaveview()
1610" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001611 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001612" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1613 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001614
1615 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1616 if exists("w:netrw_bannercnt")
1617 " start with cursor just after the banner
1618 exe w:netrw_bannercnt
1619 endif
1620 endif
1621" call Dret("netrw#Nread")
1622endfun
1623
1624" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001625" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1626" Options get restored by s:NetrwOptionsRestore()
1627"
1628" Option handling:
1629" * save user's options (s:NetrwOptionsSave)
1630" * set netrw-safe options (s:NetrwOptionsSafe)
1631" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1632" * restore user's options (s:netrwOPtionsRestore)
1633" - restore a user option when != safe option (s:NetrwRestoreSetting)
1634" vt: (variable type) normally its either "w:" or "s:"
1635fun! s:NetrwOptionsSave(vt)
1636" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1637" 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 +02001638" 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>"))
1639" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001640
1641 if !exists("{a:vt}netrw_optionsave")
1642 let {a:vt}netrw_optionsave= 1
1643 else
1644" call Dret("s:NetrwOptionsSave : options already saved")
1645 return
1646 endif
1647" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1648
1649 " Save current settings and current directory
1650" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1651 let s:yykeep = @@
1652 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1653 let {a:vt}netrw_aikeep = &l:ai
1654 let {a:vt}netrw_awkeep = &l:aw
1655 let {a:vt}netrw_bhkeep = &l:bh
1656 let {a:vt}netrw_blkeep = &l:bl
1657 let {a:vt}netrw_btkeep = &l:bt
1658 let {a:vt}netrw_bombkeep = &l:bomb
1659 let {a:vt}netrw_cedit = &cedit
1660 let {a:vt}netrw_cikeep = &l:ci
1661 let {a:vt}netrw_cinkeep = &l:cin
1662 let {a:vt}netrw_cinokeep = &l:cino
1663 let {a:vt}netrw_comkeep = &l:com
1664 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001665 let {a:vt}netrw_cuckeep = &l:cuc
1666 let {a:vt}netrw_culkeep = &l:cul
1667" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001668 let {a:vt}netrw_diffkeep = &l:diff
1669 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001670 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1671 let {a:vt}netrw_ffkeep = &l:ff
1672 endif
1673 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1674 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001675 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001676 let {a:vt}netrw_hidkeep = &l:hidden
1677 let {a:vt}netrw_imkeep = &l:im
1678 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001679 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001680 let {a:vt}netrw_lskeep = &l:ls
1681 let {a:vt}netrw_makeep = &l:ma
1682 let {a:vt}netrw_magickeep = &l:magic
1683 let {a:vt}netrw_modkeep = &l:mod
1684 let {a:vt}netrw_nukeep = &l:nu
1685 let {a:vt}netrw_rnukeep = &l:rnu
1686 let {a:vt}netrw_repkeep = &l:report
1687 let {a:vt}netrw_rokeep = &l:ro
1688 let {a:vt}netrw_selkeep = &l:sel
1689 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001690 if !g:netrw_use_noswf
1691 let {a:vt}netrw_swfkeep = &l:swf
1692 endif
1693 let {a:vt}netrw_tskeep = &l:ts
1694 let {a:vt}netrw_twkeep = &l:tw " textwidth
1695 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1696 let {a:vt}netrw_wrapkeep = &l:wrap
1697 let {a:vt}netrw_writekeep = &l:write
1698
1699 " save a few selected netrw-related variables
1700" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1701 if g:netrw_keepdir
1702 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001703" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001704 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001705 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001706 sil! let {a:vt}netrw_starkeep = @*
1707 sil! let {a:vt}netrw_pluskeep = @+
1708 endif
1709 sil! let {a:vt}netrw_slashkeep= @/
1710
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001711" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001712" 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>"))
1713" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1714endfun
1715
1716" ---------------------------------------------------------------------
1717" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1718" Use s:NetrwSaveOptions() to save user settings
1719" Use s:NetrwOptionsRestore() to restore user settings
1720fun! s:NetrwOptionsSafe(islocal)
1721" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1722" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1723" 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>"))
1724 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1725 call s:NetrwSetSafeSetting("&l:ai",0)
1726 call s:NetrwSetSafeSetting("&l:aw",0)
1727 call s:NetrwSetSafeSetting("&l:bl",0)
1728 call s:NetrwSetSafeSetting("&l:bomb",0)
1729 if a:islocal
1730 call s:NetrwSetSafeSetting("&l:bt","nofile")
1731 else
1732 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1733 endif
1734 call s:NetrwSetSafeSetting("&l:ci",0)
1735 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001736 if g:netrw_fastbrowse > a:islocal
1737 call s:NetrwSetSafeSetting("&l:bh","hide")
1738 else
1739 call s:NetrwSetSafeSetting("&l:bh","delete")
1740 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001741 call s:NetrwSetSafeSetting("&l:cino","")
1742 call s:NetrwSetSafeSetting("&l:com","")
1743 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1744 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1745 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001746 if &go =~ 'a' | set go-=a | endif
1747 if &go =~ 'A' | set go-=A | endif
1748 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001749 call s:NetrwSetSafeSetting("&l:hid",0)
1750 call s:NetrwSetSafeSetting("&l:im",0)
1751 setl isk+=@ isk+=* isk+=/
1752 call s:NetrwSetSafeSetting("&l:magic",1)
1753 if g:netrw_use_noswf
1754 call s:NetrwSetSafeSetting("swf",0)
1755 endif
1756 call s:NetrwSetSafeSetting("&l:report",10000)
1757 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1758 call s:NetrwSetSafeSetting("&l:spell",0)
1759 call s:NetrwSetSafeSetting("&l:tw",0)
1760 call s:NetrwSetSafeSetting("&l:wig","")
1761 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001762
1763 " set up cuc and cul based on g:netrw_cursor and listing style
1764 " COMBAK -- cuc cul related
1765 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001766
1767 " allow the user to override safe options
1768" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1769 if &ft == "netrw"
1770" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1771 keepalt NetrwKeepj doau FileType netrw
1772 endif
1773
1774" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1775" 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>"))
1776" call Dret("s:NetrwOptionsSafe")
1777endfun
1778
1779" ---------------------------------------------------------------------
1780" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1781fun! s:NetrwOptionsRestore(vt)
1782" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001783" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001784" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001785 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001786" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001787
1788 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1789 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001790" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001791 filetype detect
1792" 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>"))
1793 else
1794 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001795 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001796" 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 +02001797" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001798 return
1799 endif
1800 unlet {a:vt}netrw_optionsave
1801
1802 if exists("+acd")
1803 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001804" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001805 let curdir = getcwd()
1806 let &l:acd = {a:vt}netrw_acdkeep
1807 unlet {a:vt}netrw_acdkeep
1808 if &l:acd
1809 call s:NetrwLcd(curdir)
1810 endif
1811 endif
1812 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001813" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001814 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1815 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1816 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1817 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1818 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001819" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001820 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1821 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1822 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1823 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1824 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001825" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001826 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1827 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1828 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1829 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1830 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001831 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001832" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1833 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1834 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001835 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001836 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1837" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1838 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1839 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1840" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1841 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1842" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1843 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1844 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001845 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001846 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1847 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1848" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1850 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1851 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1852 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1853" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001854 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001855 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1856 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1857 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001860 call s:NetrwRestoreSetting("s:yykeep","@@")
1861 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1862 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1863 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1864 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1865
Bram Moolenaara6878372014-03-22 21:02:50 +01001866 if exists("{a:vt}netrw_swfkeep")
1867 if &directory == ""
1868 " user hasn't specified a swapfile directory;
1869 " netrw will temporarily set the swapfile directory
1870 " to the current directory as returned by getcwd().
1871 let &l:directory= getcwd()
1872 sil! let &l:swf = {a:vt}netrw_swfkeep
1873 setl directory=
1874 unlet {a:vt}netrw_swfkeep
1875 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001876 if !g:netrw_use_noswf
1877 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1878 sil! let &l:swf= {a:vt}netrw_swfkeep
1879 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001880 unlet {a:vt}netrw_swfkeep
1881 endif
1882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001883 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001884 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1885 if exists("{a:vt}netrw_dirkeep")
1886 call s:NetrwLcd(dirkeep)
1887 unlet {a:vt}netrw_dirkeep
1888 endif
1889 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001890 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001891" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001892 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1893 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001894 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001895 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001896
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001897" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1898" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1899" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1900" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1901" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001902 " Moved the filetype detect here from NetrwGetFile() because remote files
1903 " were having their filetype detect-generated settings overwritten by
1904 " NetrwOptionRestore.
1905 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001906" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1907 filetype detect
1908" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001909 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001910" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001911" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001912" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001913endfun
1914
1915" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001916" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1917" but only when the options' value and the safe setting differ
1918" Doing this means that netrw will not come up as having changed a
1919" setting last when it really didn't actually change it.
1920"
1921" Called from s:NetrwOptionsSafe
1922" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1923fun! s:NetrwSetSafeSetting(setting,safesetting)
1924" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001925
Bram Moolenaar85850f32019-07-19 22:05:51 +02001926 if a:setting =~ '^&'
1927" call Decho("fyi: a:setting starts with &")
1928 exe "let settingval= ".a:setting
1929" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001930
Bram Moolenaar85850f32019-07-19 22:05:51 +02001931 if settingval != a:safesetting
1932" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1933 if type(a:safesetting) == 0
1934 exe "let ".a:setting."=".a:safesetting
1935 elseif type(a:safesetting) == 1
1936 exe "let ".a:setting."= '".a:safesetting."'"
1937 else
1938 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1939 endif
1940 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001941 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001942
Bram Moolenaar85850f32019-07-19 22:05:51 +02001943" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001944endfun
1945
1946" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001947" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1948" but only if the setting value differs from the associated keepvar.
1949" Doing this means that netrw will not come up as having changed a
1950" setting last when it really didn't actually change it.
1951"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001952" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001953" keepvars are set up by s:NetrwOptionsSave
1954fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001955""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001956
Bram Moolenaar85850f32019-07-19 22:05:51 +02001957 " typically called from s:NetrwOptionsRestore
1958 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1959 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001960 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001961 if exists(a:keepvar)
1962 exe "let keepvarval= ".a:keepvar
1963 exe "let setting= ".a:setting
1964
1965"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1966"" call Decho("fyi: keepvarval=".keepvarval)
1967"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1968
1969 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001970"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001971 if type(a:setting) == 0
1972 exe "let ".a:setting."= ".keepvarval
1973 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001974 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001975 else
1976 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1977 endif
1978 endif
1979
1980 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001981 endif
1982
Bram Moolenaar85850f32019-07-19 22:05:51 +02001983"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001984endfun
1985
1986" ---------------------------------------------------------------------
1987" NetrwStatusLine: {{{2
1988fun! NetrwStatusLine()
1989
1990" vvv NetrwStatusLine() debugging vvv
1991" let g:stlmsg=""
1992" if !exists("w:netrw_explore_bufnr")
1993" let g:stlmsg="!X<explore_bufnr>"
1994" elseif w:netrw_explore_bufnr != bufnr("%")
1995" let g:stlmsg="explore_bufnr!=".bufnr("%")
1996" endif
1997" if !exists("w:netrw_explore_line")
1998" let g:stlmsg=" !X<explore_line>"
1999" elseif w:netrw_explore_line != line(".")
2000" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2001" endif
2002" if !exists("w:netrw_explore_list")
2003" let g:stlmsg=" !X<explore_list>"
2004" endif
2005" ^^^ NetrwStatusLine() debugging ^^^
2006
2007 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")
2008 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002009 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002010 let &laststatus = s:netrw_users_ls
2011 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2012 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2013 return ""
2014 else
2015 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2016 endif
2017endfun
2018
Bram Moolenaar85850f32019-07-19 22:05:51 +02002019" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002020" Netrw Transfer Functions: {{{1
2021" ===============================
2022
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002024" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002025" mode: =0 read remote file and insert before current line
2026" =1 read remote file and insert after current line
2027" =2 replace with remote file
2028" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002029fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002030" 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 +00002031
Bram Moolenaar5c736222010-01-06 20:54:52 +01002032 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002033 call s:NetrwOptionsSave("w:")
2034 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002035 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002036 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2037 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2038 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002039" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002040
Bram Moolenaar5c736222010-01-06 20:54:52 +01002041 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002042 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002043 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002044 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002045 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002046 elseif a:mode == 2 " replace with remote file
2047 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002048 elseif a:mode == 3 " skip read of file (leave as temporary)
2049 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002050 else
2051 exe a:mode
2052 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002055" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaar5c736222010-01-06 20:54:52 +01002057 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002058 let tmpfile= s:GetTempfile("")
2059 if tmpfile == ""
2060" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002061 return
2062 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 " attempt to repeat with previous host-file-etc
2067 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002068" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 let choice = b:netrw_lastfile
2070 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 else
2073 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002074" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002077 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002078 echomsg 'NetRead Usage:'
2079 echomsg ':Nread machine:path uses rcp'
2080 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2081 echomsg ':Nread "machine id password path" uses ftp'
2082 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2083 echomsg ':Nread fetch://machine/path uses fetch'
2084 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2085 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002086 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002087 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002088 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2089 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2090 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2091 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002092 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002093 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002094
Bram Moolenaar9964e462007-05-05 17:54:07 +00002095 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002096 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002097" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002098 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002099 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002100 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 else
2102 " case "... ... ..."
2103 let choice = strpart(choice,1,strlen(choice)-1)
2104 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002105
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 let wholechoice = wholechoice . " " . choice
2108 let ichoice = ichoice + 1
2109 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002110 if !exists("g:netrw_quiet")
2111 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2112 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002113" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 return
2115 endif
2116 let choice= a:{ichoice}
2117 endwhile
2118 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2119 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120 endif
2121 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002123" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002125
Bram Moolenaar5c736222010-01-06 20:54:52 +01002126 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002127 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002128 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002129" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002130 return
2131 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002132 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002133
Bram Moolenaar8d043172014-01-23 14:24:41 +01002134 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002135" 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 +02002136 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002138 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002139" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002142
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002143 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002145 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002146 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2147 echo "(netrw) Processing your read request..."
2148 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002149
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002151 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002154 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002156 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 " ER: the tmpfile is full path: rcp sees C:\... as host C
2158 if s:netrw_has_nt_rcp == 1
2159 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2160 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2161 else
2162 " Any way needed it machine contains a '.'
2163 let uid_machine = g:netrw_machine .'.'. $USERNAME
2164 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2167 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2168 else
2169 let uid_machine = g:netrw_machine
2170 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002172 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 +00002173 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002175
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002176 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002177 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002178 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002179" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002180 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002181 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002182 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002183 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002184 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002186 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002187 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002189 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002190 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193 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 +00002194 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 endif
2197 " 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 +00002198 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002199 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002200 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002202 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002204 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002206 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2207 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002208 q!
2209 endif
2210 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002211 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002213
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002215 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2217 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002219 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002220 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002221 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002222 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002224 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002225" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002227 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230
Bram Moolenaar97d62492012-11-15 21:28:22 +01002231 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002232 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002235 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002237 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002239 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002244
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002245 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002249 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002252 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002255
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 " perform ftp:
2257 " -i : turns off interactive prompting from ftp
2258 " -n unix : DON'T use <.netrc>, even though it exists
2259 " -n win32: quit being obnoxious about password
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."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2263 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002265 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002266 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002267 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002269 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002270 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002272
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002274 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002278 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 else
2280 let useport= ""
2281 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002282 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2283 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002284 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002285 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2286 else
2287 let tmpfile_get = tmpfile
2288 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002289 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 +00002290 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002292
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002294 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002295 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002296" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002297 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002298 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002299 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002300 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002301" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002302 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002305 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2306 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002307" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002308 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002309 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 +00002310 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002311 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 +00002312 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002313 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002314
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002315 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002316 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002317" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002318 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2319 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2321" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2322 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 +00002323 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002325 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 endif
2327 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002329 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002330
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002332 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002333 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002335
Bram Moolenaar5c736222010-01-06 20:54:52 +01002336 if !executable(g:netrw_dav_cmd)
2337 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2338" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2339 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002340 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002341 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342 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 +01002343 else
2344 " Construct execution string (four lines) which will be passed through filter
2345 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2346 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002347 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002349 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002350 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002351 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002353 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002354 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002355 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002356 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2357 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002358
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002360 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002362 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002364 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002365 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002366
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002367 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002369 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002370" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002371 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 +00002372 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002373 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002375 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002378 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002379" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002381 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002382 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002383 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002384" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002385 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002387 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 let netrw_option= "http"
2389 else
2390 let netrw_option= "ftp"
2391 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002392" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002393
Bram Moolenaar446cb832008-06-24 21:56:24 +00002394 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002395 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 +00002396 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002397 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 +00002398 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002399
Bram Moolenaar446cb832008-06-24 21:56:24 +00002400 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002402" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002403 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002406 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002407 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2409 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 +00002410 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002411 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002414 " NetRead: (file) NetRead Method #10 {{{3
2415 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002416" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2417 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002418 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2419 let b:netrw_lastfile = choice
2420
2421 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002422 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002423 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002424 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 endif
2426 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002427
Bram Moolenaar5c736222010-01-06 20:54:52 +01002428 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002430" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002431 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002432 unlet b:netrw_fname
2433 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002434 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 +01002435" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002436 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002437 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002438 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002439
Bram Moolenaar9964e462007-05-05 17:54:07 +00002440" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441endfun
2442
2443" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002444" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002445fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002447
Bram Moolenaar5c736222010-01-06 20:54:52 +01002448 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002449 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002450 call s:NetrwOptionsSave("w:")
2451 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002452
Bram Moolenaar5c736222010-01-06 20:54:52 +01002453 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454 let tmpfile= s:GetTempfile("")
2455 if tmpfile == ""
2456" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002457 return
2458 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002459
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002460 if a:0 == 0
2461 let ichoice = 0
2462 else
2463 let ichoice = 1
2464 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaar9964e462007-05-05 17:54:07 +00002466 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002467" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002468 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002469 " For binary writes, always write entire file.
2470 " (line numbers don't really make sense for that).
2471 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002472" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002473 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 elseif g:netrw_cygwin
2475 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002476 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002477" 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 +01002478 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002479 else
2480 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002481" 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 +01002482 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002483 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002484
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002486 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002487 " on the temporary file's name. Deletion of the temporary file during
2488 " cleanup then causes an error message.
2489 0file!
2490 endif
2491
Bram Moolenaar5c736222010-01-06 20:54:52 +01002492 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002493 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002494
Bram Moolenaar9964e462007-05-05 17:54:07 +00002495 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002496 " attempt to repeat with previous host-file-etc
2497 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002498" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002499 let choice = b:netrw_lastfile
2500 let ichoice= ichoice + 1
2501 else
2502 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002503
Bram Moolenaar8d043172014-01-23 14:24:41 +01002504 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002506 echomsg 'NetWrite Usage:"'
2507 echomsg ':Nwrite machine:path uses rcp'
2508 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2509 echomsg ':Nwrite "machine id password path" uses ftp'
2510 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2511 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2512 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2513 echomsg ':Nwrite rcp://machine/path uses rcp'
2514 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2515 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2516 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002517 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002519
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002520 elseif match(choice,"^\"") != -1
2521 if match(choice,"\"$") != -1
2522 " case "..."
2523 let choice=strpart(choice,1,strlen(choice)-2)
2524 else
2525 " case "... ... ..."
2526 let choice = strpart(choice,1,strlen(choice)-1)
2527 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002528
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002529 while match(choice,"\"$") == -1
2530 let wholechoice= wholechoice . " " . choice
2531 let ichoice = ichoice + 1
2532 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002533 if !exists("g:netrw_quiet")
2534 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2535 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002536" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002537 return
2538 endif
2539 let choice= a:{ichoice}
2540 endwhile
2541 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2542 endif
2543 endif
2544 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002546" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002547
Bram Moolenaar9964e462007-05-05 17:54:07 +00002548 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002549 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002550 if !exists("b:netrw_method") || b:netrw_method < 0
2551" call Dfunc("netrw#NetWrite : unsupported method")
2552 return
2553 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002554
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002555 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002556 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002557 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002558 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2559 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002560" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002561 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002562
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002563 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002565 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002566" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 if s:netrw_has_nt_rcp == 1
2568 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2569 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2570 else
2571 let uid_machine = g:netrw_machine .'.'. $USERNAME
2572 endif
2573 else
2574 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2575 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2576 else
2577 let uid_machine = g:netrw_machine
2578 endif
2579 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002580 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 +00002581 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002582
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002584 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002585 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002586" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002587 let netrw_fname = b:netrw_fname
2588
2589 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2590 let bhkeep = &l:bh
2591 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002592 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002594
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002596 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002597 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002599 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002600 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002602 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002603 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606 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 +00002607 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2609 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 endif
2611 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2612 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002613 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002615 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002616 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002618
2619 " remove enew buffer (quietly)
2620 let filtbuf= bufnr("%")
2621 exe curbuf."b!"
2622 let &l:bh = bhkeep
2623 exe filtbuf."bw!"
2624
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002626
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002628 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002629 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002630 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002631" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002632 let netrw_fname = b:netrw_fname
2633 let bhkeep = &l:bh
2634
2635 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2636 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002637 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002638 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002639 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002642 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002644 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002645 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002646" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002648 if exists("g:netrw_uid") && g:netrw_uid != ""
2649 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002650 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002652 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002653 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002654 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002656 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002663 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002666 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002669 " save choice/id/password for future use
2670 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002671
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 " perform ftp:
2673 " -i : turns off interactive prompting from ftp
2674 " -n unix : DON'T use <.netrc>, even though it exists
2675 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002676 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2679 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002680 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002681 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002682 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 let mod=1
2684 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002685
2686 " remove enew buffer (quietly)
2687 let filtbuf= bufnr("%")
2688 exe curbuf."b!"
2689 let &l:bh= bhkeep
2690 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002691
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002693 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002694 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002695" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002696 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002697 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 else
2699 let useport= ""
2700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002701 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 +00002702 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002703
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002705 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002708 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2709 if executable(curl)
2710 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711 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 +01002712 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002713 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002714 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002715
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002717 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002718 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002719" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002720
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002721 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002722 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2723 let bhkeep = &l:bh
2724
2725 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2726 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002727 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002728 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729
Bram Moolenaarff034192013-04-24 18:51:19 +02002730 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002731 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002732 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002733 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002734 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002735 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002736 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002737 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002738 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002739 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002740
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002742 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002744
2745 " remove enew buffer (quietly)
2746 let filtbuf= bufnr("%")
2747 exe curbuf."b!"
2748 let &l:bh = bhkeep
2749 exe filtbuf."bw!"
2750
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002752
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002754 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002755 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002756" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002757 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 +00002758 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002759
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002760 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002761 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002762 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002763" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002764 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2766 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2767 else
2768 let uid_machine = g:netrw_machine
2769 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002770
2771 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2772 let bhkeep = &l:bh
2773 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002774 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002775 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002776
Bram Moolenaarff034192013-04-24 18:51:19 +02002777 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002778 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002780 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002781 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002782 let filtbuf= bufnr("%")
2783 exe curbuf."b!"
2784 let &l:bh = bhkeep
2785 exe filtbuf."bw!"
2786 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002787
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002788 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002790 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002791 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002792 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002794 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002795
Bram Moolenaar5c736222010-01-06 20:54:52 +01002796 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002797" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002798 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002799" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002800 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002802 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002804 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002806 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002807" 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 +02002808 elseif !exists("leavemod")
2809 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002811 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002812" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002814
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002816endfun
2817
2818" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002819" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002820" uses NetRead to get a copy of the file into a temporarily file,
2821" then sources that file,
2822" then removes that file.
2823fun! netrw#NetSource(...)
2824" call Dfunc("netrw#NetSource() a:0=".a:0)
2825 if a:0 > 0 && a:1 == '?'
2826 " give help
2827 echomsg 'NetSource Usage:'
2828 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2829 echomsg ':Nsource fetch://machine/path uses fetch'
2830 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002831 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002832 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2833 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2834 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2835 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2836 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002837 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002838 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002839 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002840 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002841" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002842 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002843" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002844 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002845" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002846 if delete(s:netrw_tmpfile)
2847 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2848 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 unlet s:netrw_tmpfile
2850 else
2851 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2852 endif
2853 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002854 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 endif
2856" call Dret("netrw#NetSource")
2857endfun
2858
Bram Moolenaar8d043172014-01-23 14:24:41 +01002859" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002860" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2861" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002862fun! netrw#SetTreetop(iscmd,...)
2863" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2864" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002865
Bram Moolenaar85850f32019-07-19 22:05:51 +02002866 " iscmd==0: netrw#SetTreetop called using gn mapping
2867 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2868" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002869 " clear out the current tree
2870 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002871" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002872 let inittreetop= w:netrw_treetop
2873 unlet w:netrw_treetop
2874 endif
2875 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002876" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002877 unlet w:netrw_treedict
2878 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002879" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002880
Bram Moolenaar85850f32019-07-19 22:05:51 +02002881 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002882 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002883" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002885 if isdirectory(s:NetrwFile(a:1))
2886" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002887 let treedir = a:1
2888 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002890 let treedir = b:netrw_curdir."/".a:1
2891 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002892" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894 " normally the cursor is left in the message window.
2895 " However, here this results in the directory being listed in the message window, which is not wanted.
2896 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002899 let treedir = "."
2900 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002901 endif
2902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002904
2905 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906 let islocal= expand("%") !~ '^\a\{3,}://'
2907" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002908
2909 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002910 if islocal
2911 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2912 else
2913 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2914 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002915
Bram Moolenaara6878372014-03-22 21:02:50 +01002916" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002917endfun
2918
Bram Moolenaar9964e462007-05-05 17:54:07 +00002919" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002920" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002921" readcmd == %r : replace buffer with newly read file
2922" == 0r : read file at top of buffer
2923" == r : read file after current line
2924" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002925fun! s:NetrwGetFile(readcmd, tfile, method)
2926" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002927
2928 " readcmd=='t': simply do nothing
2929 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002930" 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 +01002931" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002932 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002933 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002934
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935 " get name of remote filename (ie. url and all)
2936 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002937" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002938
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939 if exists("*NetReadFixup")
2940 " for the use of NetReadFixup (not otherwise used internally)
2941 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002942 endif
2943
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944 if a:readcmd[0] == '%'
2945 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947
2948 " rename the current buffer to the temp file (ie. tfile)
2949 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002950 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 else
2952 let tfile= a:tfile
2953 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002954 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955
2956 " edit temporary file (ie. read the temporary file in)
2957 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002958" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 call zip#Browse(tfile)
2960 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002961" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002962 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002963 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002964" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002966 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002969 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002971 call tar#Browse(tfile)
2972 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002977 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 endif
2979
2980 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002981 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002982
Bram Moolenaar71badf92023-04-22 22:40:14 +01002983 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002984 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002985 " Note that isk must not include a "/" for scripts.vim
2986 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002987" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2988" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002989" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002990" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2991 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002992 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002993 filetype detect
2994" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002995 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002996" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002997 let line1 = 1
2998 let line2 = line("$")
2999
Bram Moolenaar8d043172014-01-23 14:24:41 +01003000 elseif !&ma
3001 " 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 +01003002 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003003" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003004 return
3005
Bram Moolenaar9964e462007-05-05 17:54:07 +00003006 elseif s:FileReadable(a:tfile)
3007 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003008" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003009 let curline = line(".")
3010 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003012 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003013 let line1= curline + 1
3014 let line2= line("$") - lastline + 1
3015
3016 else
3017 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3019" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003020 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003021" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 return
3023 endif
3024
3025 " User-provided (ie. optional) fix-it-up command
3026 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003027" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003028 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003030" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003031 endif
3032
Bram Moolenaaradc21822011-04-01 18:03:16 +02003033 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003034 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003035 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003036 endif
3037
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" 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 +00003039
3040 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003041" redraw!
3042
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" 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 +00003044" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003045endfun
3046
Bram Moolenaar9964e462007-05-05 17:54:07 +00003047" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003048" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003049" Input:
3050" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3051" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003052" b:netrw_method= 1: rcp
3053" 2: ftp + <.netrc>
3054" 3: ftp + machine, id, password, and [path]filename
3055" 4: scp
3056" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003057" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003058" 7: rsync
3059" 8: fetch
3060" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003061" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003062" g:netrw_machine= hostname
3063" b:netrw_fname = filename
3064" g:netrw_port = optional port number (for ftp)
3065" g:netrw_choice = copy of input url (choice)
3066fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003067" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003068
Bram Moolenaar251e1912011-06-19 05:09:16 +02003069 " sanity check: choice should have at least three slashes in it
3070 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3071 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3072 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003073" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003074 return
3075 endif
3076
Bram Moolenaar5c736222010-01-06 20:54:52 +01003077 " record current g:netrw_machine, if any
3078 " curmachine used if protocol == ftp and no .netrc
3079 if exists("g:netrw_machine")
3080 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003081" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003082 else
3083 let curmachine= "N O T A HOST"
3084 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003085 if exists("g:netrw_port")
3086 let netrw_port= g:netrw_port
3087 endif
3088
3089 " insure that netrw_ftp_cmd starts off every method determination
3090 " with the current g:netrw_ftp_cmd
3091 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003092
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003093 " initialization
3094 let b:netrw_method = 0
3095 let g:netrw_machine = ""
3096 let b:netrw_fname = ""
3097 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003098 let g:netrw_choice = a:choice
3099
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003100 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003101 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003102 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3103 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003104 " rcpurm : rcp://[user@]host/filename Use rcp
3105 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003107 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003108 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 " rsyncurm : rsync://host[:port]/path Use rsync
3110 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3111 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003112 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3114 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003115 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3116 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003118 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003119 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003120 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003122 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003124 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003125
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003126" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003128 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003130" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003131 let b:netrw_method = 1
3132 let userid = substitute(a:choice,rcpurm,'\1',"")
3133 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3134 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 if userid != ""
3136 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003138
Bram Moolenaaradc21822011-04-01 18:03:16 +02003139 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003141" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003142 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003143 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3144 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3145 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003146
Bram Moolenaar15146672011-10-20 22:22:38 +02003147 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003149" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003150 let b:netrw_method = 5
3151 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3152 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003153 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaaradc21822011-04-01 18:03:16 +02003155 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003158 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003159 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003160 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3161 else
3162 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3163 endif
3164 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003165
Bram Moolenaaradc21822011-04-01 18:03:16 +02003166 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003167 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003168" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 let b:netrw_method = 7
3170 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3171 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003172
Bram Moolenaaradc21822011-04-01 18:03:16 +02003173 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003175" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003176 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3178 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3179 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003180" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 if userid != ""
3182 let g:netrw_uid= userid
3183 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003184
Bram Moolenaaradc21822011-04-01 18:03:16 +02003185 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003186 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003187 call NetUserPass("ftp:".g:netrw_machine)
3188 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003189 " if there's a change in hostname, require password re-entry
3190 unlet s:netrw_passwd
3191 endif
3192 if exists("netrw_port")
3193 unlet netrw_port
3194 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003195 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003196
Bram Moolenaar446cb832008-06-24 21:56:24 +00003197 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003198 let b:netrw_method = 3
3199 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200 let host= substitute(g:netrw_machine,'\..*$','','')
3201 if exists("s:netrw_hup[host]")
3202 call NetUserPass("ftp:".host)
3203
Nir Lichtman1e34b952024-05-08 19:19:34 +02003204 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003205" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3206" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003207 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003208 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003209" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003210 endif
3211 let b:netrw_method= 2
3212 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003213" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003214 let b:netrw_method= 2
3215 else
3216 if !exists("g:netrw_uid") || g:netrw_uid == ""
3217 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003218 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003219 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003220 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003221 endif
3222 let b:netrw_method= 3
3223 endif
3224 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003225
Bram Moolenaaradc21822011-04-01 18:03:16 +02003226 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003228" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003229 let b:netrw_method = 8
3230 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3231 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3232 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3233 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003234
Bram Moolenaaradc21822011-04-01 18:03:16 +02003235 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003237" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003239 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3240 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003241 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003242 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003243 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003244
Bram Moolenaaradc21822011-04-01 18:03:16 +02003245 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003246 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003247" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003248 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 let b:netrw_method = 3
3250 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3251 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003252
Bram Moolenaar9964e462007-05-05 17:54:07 +00003253 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003254 let b:netrw_method = 2
3255 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3256 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3257 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003258
Bram Moolenaaradc21822011-04-01 18:03:16 +02003259 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003260 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003261" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 let b:netrw_method = 9
3263 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3264 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003265
Bram Moolenaaradc21822011-04-01 18:03:16 +02003266 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003267 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003268" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003269 let b:netrw_method = 1
3270 let userid = substitute(a:choice,rcphf,'\2',"")
3271 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3272 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003273" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3274" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3275" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3276" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003277 if userid != ""
3278 let g:netrw_uid= userid
3279 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003280
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003281 " Method#10: file://user@hostname/...path-to-file {{{3
3282 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003283" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003284 let b:netrw_method = 10
3285 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003286" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003287
Bram Moolenaaradc21822011-04-01 18:03:16 +02003288 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003289 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003290 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003291 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003292 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003293 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003295 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003296
Bram Moolenaar81695252004-12-29 20:58:21 +00003297 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003298 " remove any leading [:#] from port number
3299 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3300 elseif exists("netrw_port")
3301 " retain port number as implicit for subsequent ftp operations
3302 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003303 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003304
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003305" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3306" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3307" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3308" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003309" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003310" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003311" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003312" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003313" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003314" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003315" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003316" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318
Bram Moolenaar9964e462007-05-05 17:54:07 +00003319" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003320" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003321" Usage: :call NetUserPass() -- will prompt for userid and password
3322" :call NetUserPass("uid") -- will prompt for password
3323" :call NetUserPass("uid","password") -- sets global userid and password
3324" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3325" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326fun! NetUserPass(...)
3327
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003328" call Dfunc("NetUserPass() a:0=".a:0)
3329
3330 if !exists('s:netrw_hup')
3331 let s:netrw_hup= {}
3332 endif
3333
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003335 " case: no input arguments
3336
3337 " change host and username if not previously entered; get new password
3338 if !exists("g:netrw_machine")
3339 let g:netrw_machine= input('Enter hostname: ')
3340 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003342 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343 let g:netrw_uid= input('Enter username: ')
3344 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003345 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003346 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003347
3348 " set up hup database
3349 let host = substitute(g:netrw_machine,'\..*$','','')
3350 if !exists('s:netrw_hup[host]')
3351 let s:netrw_hup[host]= {}
3352 endif
3353 let s:netrw_hup[host].uid = g:netrw_uid
3354 let s:netrw_hup[host].passwd = s:netrw_passwd
3355
3356 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003357 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003358
3359 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003360 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003361 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003362" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003363 let host = substitute(a:1,'^ftp:','','')
3364 let host = substitute(host,'\..*','','')
3365 if exists("s:netrw_hup[host]")
3366 let g:netrw_uid = s:netrw_hup[host].uid
3367 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003368" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3369" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003370 else
3371 let g:netrw_uid = input("Enter UserId: ")
3372 let s:netrw_passwd = inputsecret("Enter Password: ")
3373 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003374
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003375 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003376 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003377" 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 +02003378 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003379 if g:netrw_machine =~ '[0-9.]\+'
3380 let host= g:netrw_machine
3381 else
3382 let host= substitute(g:netrw_machine,'\..*$','','')
3383 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003384 else
3385 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003386 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003388" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003389 if exists("g:netrw_passwd")
3390 " ask for password if one not previously entered
3391 let s:netrw_passwd= g:netrw_passwd
3392 else
3393 let s:netrw_passwd = inputsecret("Enter Password: ")
3394 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003395 endif
3396
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003397" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003398 if exists("host")
3399 if !exists('s:netrw_hup[host]')
3400 let s:netrw_hup[host]= {}
3401 endif
3402 let s:netrw_hup[host].uid = g:netrw_uid
3403 let s:netrw_hup[host].passwd = s:netrw_passwd
3404 endif
3405
3406 elseif a:0 == 2
3407 let g:netrw_uid = a:1
3408 let s:netrw_passwd = a:2
3409
3410 elseif a:0 == 3
3411 " enter hostname, user-id, and password into the hup dictionary
3412 let host = substitute(a:1,'^\a\+:','','')
3413 let host = substitute(host,'\..*$','','')
3414 if !exists('s:netrw_hup[host]')
3415 let s:netrw_hup[host]= {}
3416 endif
3417 let s:netrw_hup[host].uid = a:2
3418 let s:netrw_hup[host].passwd = a:3
3419 let g:netrw_uid = s:netrw_hup[host].uid
3420 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003421" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3422" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003424
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003425" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427
Bram Moolenaar85850f32019-07-19 22:05:51 +02003428" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003429" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003430" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003432" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003433" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3434fun! s:ExplorePatHls(pattern)
3435" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3436 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003437" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003438 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003439" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003440 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3441" call Dret("s:ExplorePatHls repat<".repat.">")
3442 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003443endfun
3444
3445" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003446" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003447" 0: (user: <mb>) bookmark current directory
3448" 1: (user: <gb>) change to the bookmarked directory
3449" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003450" 3: (browsing) records current directory history
3451" 4: (user: <u>) go up (previous) directory, using history
3452" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003453" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003454fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003455" 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 +02003456 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3457" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3458 return
3459 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003460
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003461 let ykeep = @@
3462 let curbufnr = bufnr("%")
3463
Bram Moolenaar9964e462007-05-05 17:54:07 +00003464 if a:chg == 0
3465 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003466" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003467 if exists("s:netrwmarkfilelist_{curbufnr}")
3468 call s:NetrwBookmark(0)
3469 echo "bookmarked marked files"
3470 else
3471 call s:MakeBookmark(a:curdir)
3472 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003473 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003474
KSR-Yasudaf4498252023-10-06 03:34:17 +09003475 try
3476 call s:NetrwBookHistSave()
3477 catch
3478 endtry
3479
Bram Moolenaar9964e462007-05-05 17:54:07 +00003480 elseif a:chg == 1
3481 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003482" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003483 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003484" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003485 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003486 else
3487 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3488 endif
3489
3490 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003491" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003492 let didwork= 0
3493 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003494" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003495 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003496" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003497 let cnt= 1
3498 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003499" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003500 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003501 let didwork = 1
3502 let cnt = cnt + 1
3503 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003504 endif
3505
3506 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003507 " Note: history is saved only when PerformListing is done;
3508 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3509 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003510 let first = 1
3511 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003512 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003513 while ( first || cnt != g:netrw_dirhistcnt )
3514" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003515 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003516" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003517 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003518 let didwork= 1
3519 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003520 let histcnt = histcnt + 1
3521 let first = 0
3522 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003523 if cnt < 0
3524 let cnt= cnt + g:netrw_dirhistmax
3525 endif
3526 endwhile
3527 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003528 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003529 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003530 if didwork
3531 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3532 endif
3533
3534 elseif a:chg == 3
3535 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003536" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003537 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 +02003538 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003539 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3540 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003541 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003542" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003543 endif
3544
3545 elseif a:chg == 4
3546 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003547" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003548 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003549 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3550 if g:netrw_dirhistcnt < 0
3551 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003552 endif
3553 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003554 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003555 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3557" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003558 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003559 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003560" call Decho("setl ma noro",'~'.expand("<slnum>"))
3561 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003562 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003563" call Decho("setl nomod",'~'.expand("<slnum>"))
3564" 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 +00003565 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003566" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3567 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003568 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003569 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003571 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003572 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003573 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003574 echo "Sorry, no predecessor directory exists yet"
3575 endif
3576
3577 elseif a:chg == 5
3578 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003579" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003581 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3582 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3583" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003584 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003585" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003586 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003587 sil! NetrwKeepj %d _
3588" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3589" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003590 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003591" 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 +02003592 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003593" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3594 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003595 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003596 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3597 if g:netrw_dirhistcnt < 0
3598 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003599 endif
3600 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003601 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003602 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003603 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003604 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003605 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003606
3607 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003608" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003609 if exists("s:netrwmarkfilelist_{curbufnr}")
3610 call s:NetrwBookmark(1)
3611 echo "removed marked files from bookmarks"
3612 else
3613 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003614 let iremove = v:count
3615 let dremove = g:netrw_bookmarklist[iremove - 1]
3616" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003617 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003618" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3619 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3620 echo "removed ".dremove." from g:netrw_bookmarklist"
3621" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003622 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003623" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003624
3625 try
3626 call s:NetrwBookHistSave()
3627 catch
3628 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003629 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003630 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003631 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003632 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003633" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003634endfun
3635
3636" ---------------------------------------------------------------------
3637" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003638" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003639" Sister function: s:NetrwBookHistSave()
3640fun! s:NetrwBookHistRead()
3641" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003642 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003643" 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 +02003644 return
3645 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003646 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003647
3648 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003649 if !exists("s:netrw_initbookhist")
3650 let home = s:NetrwHome()
3651 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003652 if filereadable(s:NetrwFile(savefile))
3653" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003654 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003655 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003656
3657 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003658 if g:netrw_dirhistmax > 0
3659 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003660 if filereadable(s:NetrwFile(savefile))
3661" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003662 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003663 endif
3664 let s:netrw_initbookhist= 1
3665 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003666 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003667 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003668
Bram Moolenaar97d62492012-11-15 21:28:22 +01003669 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003670" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3671" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003672" call Dret("s:NetrwBookHistRead")
3673endfun
3674
3675" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003676" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003677" Sister function: s:NetrwBookHistRead()
3678" I used to do this via viminfo but that appears to
3679" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003680" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3681" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003682" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003684" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003685 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003687 return
3688 endif
3689
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003692 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003693
3694 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003697 if g:netrw_use_noswf
3698 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3699 else
3700 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3701 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003702 setl nocin noai noci magic nospell nohid wig= noaw
3703 setl ma noro write
3704 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003705 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706
Bram Moolenaar85850f32019-07-19 22:05:51 +02003707 " rename enew'd file: .netrwhist -- no attempt to merge
3708 " record dirhistmax and current dirhistcnt
3709 " save history
3710" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003711 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003712 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3714 if g:netrw_dirhistmax > 0
3715 let lastline = line("$")
3716 let cnt = g:netrw_dirhistcnt
3717 let first = 1
3718 while ( first || cnt != g:netrw_dirhistcnt )
3719 let lastline= lastline + 1
3720 if exists("g:netrw_dirhist_{cnt}")
3721 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3722" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3723 endif
3724 let first = 0
3725 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3726 if cnt < 0
3727 let cnt= cnt + g:netrw_dirhistmax
3728 endif
3729 endwhile
3730 exe "sil! w! ".savefile
3731" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3732 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003733
Bram Moolenaar85850f32019-07-19 22:05:51 +02003734 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003735 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003736 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003737" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003738 " merge and write .netrwbook
3739 let savefile= s:NetrwHome()."/.netrwbook"
3740
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003741 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003743 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744 for bdm in booklist
3745 if index(g:netrw_bookmarklist,bdm) == -1
3746 call add(g:netrw_bookmarklist,bdm)
3747 endif
3748 endfor
3749 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 endif
3751
3752 " construct and save .netrwbook
3753 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003754 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003755" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003757
3758 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759 let bgone= bufnr("%")
3760 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003761 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003762
3763" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003764endfun
3765
3766" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003767" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3768" list of the contents of a local or remote directory. It is assumed that the
3769" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3770" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003771" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003772fun! s:NetrwBrowse(islocal,dirname)
3773 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003774" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003775" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3776" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3777" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003778
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003779 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3780 " This is useful when one edits a local file, then :e ., then :Rex
3781 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3782 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003783" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003784 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003785
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003786 " s:NetrwBrowse : initialize history {{{3
3787 if !exists("s:netrw_initbookhist")
3788 NetrwKeepj call s:NetrwBookHistRead()
3789 endif
3790
3791 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003792 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003794" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003795 else
3796 let dirname= a:dirname
3797 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003798
Bram Moolenaar85850f32019-07-19 22:05:51 +02003799 " repoint t:netrw_lexbufnr if appropriate
3800 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3801" call Decho("set repointlexbufnr to true!")
3802 let repointlexbufnr= 1
3803 endif
3804
3805 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806 if exists("s:netrw_skipbrowse")
3807 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003808" 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 +01003809" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810 return
3811 endif
3812 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003813 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814" call Dret("s:NetrwBrowse : missing shellescape()")
3815 return
3816 endif
3817 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003818 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819" call Dret("s:NetrwBrowse : missing fnameescape()")
3820 return
3821 endif
3822
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003823 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003824 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003825
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003827 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3828 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3829" call Decho("clearing marked files",'~'.expand("<slnum>"))
3830 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3831 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003832 endif
3833
3834 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003836" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3837" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003838 if s:NetrwLcd(dirname)
3839" call Dret("s:NetrwBrowse : lcd failure")
3840 return
3841 endif
3842 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003843" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844
Bram Moolenaar5c736222010-01-06 20:54:52 +01003845 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003846 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003847" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003848 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003849" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003850 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003851 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003852 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003854
3855 " remove any filetype indicator from end of dirname, except for the
3856 " "this is a directory" indicator (/).
3857 " There shouldn't be one of those here, anyway.
3858 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 call s:RemotePathAnalysis(dirname)
3861
3862 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3863 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003864 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867 let b:netrw_curdir = dirname
3868 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003869 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3871 sil call netrw#NetRead(2,url)
3872 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003873" call Decho("url<".url.">",'~'.expand("<slnum>"))
3874" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3875" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 if s:path =~ '.bz2'
3877 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3878 elseif s:path =~ '.gz'
3879 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3880 elseif s:path =~ '.gz'
3881 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3882 else
3883 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3884 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003885 endif
3886
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003887 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003888 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003889 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003890" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003891 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003892" 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 +00003893
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894" call Dret("s:NetrwBrowse : file<".s:fname.">")
3895 return
3896 endif
3897
Bram Moolenaaradc21822011-04-01 18:03:16 +02003898 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003899 call s:UseBufWinVars()
3900
3901 " set up some variables {{{3
3902 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003903 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904 let s:last_sort_by = g:netrw_sort_by
3905
3906 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003907 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003908
Bram Moolenaar97d62492012-11-15 21:28:22 +01003909 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003910" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003911 let svpos = winsaveview()
3912" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003914
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003916 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3917 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3918" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3919" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3920 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3921 else
3922" " call Decho("2match none",'~'.expand("<slnum>"))
3923 2match none
3924 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003926 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003927 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003928" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003929 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003930" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003931" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003932 return
3933 endif
3934
3935 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003936" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003937 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938 if b:netrw_curdir =~ '[/\\]$'
3939 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3940 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003941 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003942 let b:netrw_curdir= b:netrw_curdir."/"
3943 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003944 if b:netrw_curdir == ''
3945 if has("amiga")
3946 " On the Amiga, the empty string connotes the current directory
3947 let b:netrw_curdir= getcwd()
3948 else
3949 " under unix, when the root directory is encountered, the result
3950 " from the preceding substitute is an empty string.
3951 let b:netrw_curdir= '/'
3952 endif
3953 endif
3954 if !a:islocal && b:netrw_curdir !~ '/$'
3955 let b:netrw_curdir= b:netrw_curdir.'/'
3956 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958
3959 " ------------
3960 " (local only) {{{3
3961 " ------------
3962 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003963" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003964
3965 " Set up ShellCmdPost handling. Append current buffer to browselist
3966 call s:LocalFastBrowser()
3967
3968 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3969 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3971" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003972 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003973 if s:NetrwLcd(b:netrw_curdir)
3974" call Dret("s:NetrwBrowse : lcd failure")
3975 return
3976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003977 endif
3978 endif
3979
3980 " --------------------------------
3981 " remote handling: {{{3
3982 " --------------------------------
3983 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003984" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985
Bram Moolenaar97d62492012-11-15 21:28:22 +01003986 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003988 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003989 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003990" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003991 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3992 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3993 if dirname !~ '/$'
3994 let dirname= dirname.'/'
3995 endif
3996 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003999 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001 endif
4002
4003 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4004 if dirname !~ dirpat
4005 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004006 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004008 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004009" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004010 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011" 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 +00004012" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4013 return
4014 endif
4015 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004017 endif " (additional remote handling)
4018
Bram Moolenaar85850f32019-07-19 22:05:51 +02004019 " -------------------------------
4020 " Perform Directory Listing: {{{3
4021 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004022 NetrwKeepj call s:NetrwMaps(a:islocal)
4023 NetrwKeepj call s:NetrwCommands(a:islocal)
4024 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004025
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004026 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004027 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004028" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4029
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004030 " If there is a rexposn: restore position with rexposn
4031 " Otherwise : set rexposn
4032 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004033" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4034 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4035 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4036 NetrwKeepj exe w:netrw_bannercnt
4037 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004038 else
4039 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4040 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004041 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004042 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004044 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004045 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004046
Bram Moolenaar85850f32019-07-19 22:05:51 +02004047 " repoint t:netrw_lexbufnr if appropriate
4048 if exists("repointlexbufnr")
4049 let t:netrw_lexbufnr= bufnr("%")
4050" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4051 endif
4052
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004053 " restore position
4054 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004055" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4056 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004057 endif
4058
Bram Moolenaara6878372014-03-22 21:02:50 +01004059 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004060 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4061 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004062" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4063" 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 +02004064" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004065 return
4066endfun
4067
4068" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4070" may not apply correctly; ie. netrw's idea of the current directory may
4071" differ from vim's. This function insures that netrw's idea of the current
4072" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004073" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004075" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4076" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4077" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4078" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4079" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004080
4081 " clean up any leading treedepthstring
4082 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4083 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004084" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004085 else
4086 let fname= a:fname
4087 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004088
4089 if g:netrw_keepdir
4090 " vim's idea of the current directory possibly may differ from netrw's
4091 if !exists("b:netrw_curdir")
4092 let b:netrw_curdir= getcwd()
4093 endif
4094
Nir Lichtman1e34b952024-05-08 19:19:34 +02004095 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004096 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004097 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004098 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004099" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004100 else
4101 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004102 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004103" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104 endif
4105
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004106 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004108 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004109" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110 else
4111 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004113" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 endif
4115 else
4116 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4119" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4120" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121 endif
4122
Bram Moolenaar85850f32019-07-19 22:05:51 +02004123" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124 return ret
4125endfun
4126
4127" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004128" s:NetrwFileInfo: supports qf (query for file information) {{{2
4129fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004130" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004131 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004132 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004133 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004134 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004135 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004136 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004137 let lsopt= "-lsadh --si"
4138 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004139" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004140 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004141
4142 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004143 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004144" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004145
Bram Moolenaara6878372014-03-22 21:02:50 +01004146 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004147 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004148" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004149
4150 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004153
Bram Moolenaar446cb832008-06-24 21:56:24 +00004154 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004158 endif
4159 else
4160 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4162 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004163 let fname= substitute(a:fname,".$","","")
4164 else
4165 let fname= a:fname
4166 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167 let t = getftime(s:NetrwFile(fname))
4168 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004169 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004170 let sz= s:NetrwHumanReadable(sz)
4171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004172 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4173" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174 endif
4175 else
4176 echo "sorry, \"qf\" not supported yet for remote files"
4177 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004178 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179" call Dret("s:NetrwFileInfo")
4180endfun
4181
4182" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004183" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4184fun! s:NetrwFullPath(filename)
4185" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4186 let filename= a:filename
4187 if filename !~ '^/'
4188 let filename= resolve(getcwd().'/'.filename)
4189 endif
4190 if filename != "/" && filename =~ '/$'
4191 let filename= substitute(filename,'/$','','')
4192 endif
4193" " call Dret("s:NetrwFullPath <".filename.">")
4194 return filename
4195endfun
4196
4197" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004198" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004199" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004200" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004201" 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 +00004202fun! s:NetrwGetBuffer(islocal,dirname)
4203" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004204" 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 +02004205" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4206" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207 let dirname= a:dirname
4208
4209 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004210" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004211 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004212" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004213 let s:netrwbuf= {}
4214 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004215" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4216" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4217
4218 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4219 let bufnum = -1
4220
4221 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4222 if has_key(s:netrwbuf,"NetrwTreeListing")
4223 let bufnum= s:netrwbuf["NetrwTreeListing"]
4224 else
4225 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4226 endif
4227" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4228 if !bufexists(bufnum)
4229 call remove(s:netrwbuf,"NetrwTreeListing"])
4230 let bufnum= -1
4231 endif
4232 elseif bufnr("NetrwTreeListing") != -1
4233 let bufnum= bufnr("NetrwTreeListing")
4234" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4235 else
4236" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4237 let bufnum= -1
4238 endif
4239
4240 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004241 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004242" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004243 if !bufexists(bufnum)
4244 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4245 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004247
Bram Moolenaar446cb832008-06-24 21:56:24 +00004248 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004249" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004250 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004251 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004252" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4253
Bram Moolenaar71badf92023-04-22 22:40:14 +01004254 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004255 " IF the buffer already has the desired name
4256 " AND it is empty
4257 let curbuf = bufname("%")
4258 if curbuf == '.'
4259 let curbuf = getcwd()
4260 endif
4261" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004262" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004263" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4264" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4265" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4266" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4267 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004268" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4269 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004270 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004271" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004272 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004273 " 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 +00004274
4275 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004276 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004277" 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 +00004278 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004279" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004280 " name the buffer
4281 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4282 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004283" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004284 let w:netrw_treebufnr = bufnr("%")
4285 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004286 if g:netrw_use_noswf
4287 setl nobl bt=nofile noswf
4288 else
4289 setl nobl bt=nofile
4290 endif
4291 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4292 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4293 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4294 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004295" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004297 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004298 " enter the new buffer into the s:netrwbuf dictionary
4299 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4300" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4301" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004302 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004303" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004304
4305 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004306" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004307 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004309 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004310
4311 if &ft == "netrw"
4312" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4313 exe "sil! NetrwKeepj noswapfile b ".bufnum
4314" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004316" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4317 call s:NetrwEditBuf(bufnum)
4318" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004319 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004320" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004321 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004322 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004324
4325 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004327
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004328 if line("$") <= 1 && getline(1) == ""
4329 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004330 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004331" 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>"))
4332" 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 +01004333" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4334 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004335
Bram Moolenaar97d62492012-11-15 21:28:22 +01004336 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004338 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339 sil NetrwKeepj %d _
4340" 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>"))
4341" 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 +01004342" 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 +00004343 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004344
Bram Moolenaar446cb832008-06-24 21:56:24 +00004345 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004346" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4347" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004348 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004350 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4352" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004353" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004355
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004357" 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>"))
4358" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4359" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360 return 1
4361 endif
4362 endif
4363
4364 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4365 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4366 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4367 " med 1 D H
4368 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004369" 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 +00004370 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004371 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004372 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004373
4374 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004375" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4376" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4377 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004379" 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>"))
4380" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4381" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004382 return 0
4383endfun
4384
4385" ---------------------------------------------------------------------
4386" s:NetrwGetcwd: get the current directory. {{{2
4387" Change backslashes to forward slashes, if any.
4388" If doesc is true, escape certain troublesome characters
4389fun! s:NetrwGetcwd(doesc)
4390" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4391 let curdir= substitute(getcwd(),'\\','/','ge')
4392 if curdir !~ '[\/]$'
4393 let curdir= curdir.'/'
4394 endif
4395 if a:doesc
4396 let curdir= fnameescape(curdir)
4397 endif
4398" call Dret("NetrwGetcwd <".curdir.">")
4399 return curdir
4400endfun
4401
4402" ---------------------------------------------------------------------
4403" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4404fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004405" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4406" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4407 let keepsol= &l:sol
4408 setl nosol
4409
Bram Moolenaar446cb832008-06-24 21:56:24 +00004410 call s:UseBufWinVars()
4411
4412 " insure that w:netrw_liststyle is set up
4413 if !exists("w:netrw_liststyle")
4414 if exists("g:netrw_liststyle")
4415 let w:netrw_liststyle= g:netrw_liststyle
4416 else
4417 let w:netrw_liststyle= s:THINLIST
4418 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004419" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004420 endif
4421
4422 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4423 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004424" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004425 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 let dirname= "./"
4427 let curline= getline('.')
4428
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004429 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004430 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431 let s:netrw_skipbrowse= 1
4432 echo 'Pressing "s" also works'
4433
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004434 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435 let s:netrw_skipbrowse= 1
4436 echo 'Press "S" to edit sorting sequence'
4437
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004438 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004439 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004442 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004443 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 let s:netrw_skipbrowse= 1
4445 echo 'Pressing "a" also works'
4446
4447 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004448 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449 endif
4450
4451 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004452" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004453 NetrwKeepj norm! 0
4454 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455
4456 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004457" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004458 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4460
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004461 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004462" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004463 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004464 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465
4466 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468 let dirname= getline('.')
4469
4470 if !exists("b:netrw_cpf")
4471 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004472 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 +01004473 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004474" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 endif
4476
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004477" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004479" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4480" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004482 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 else
4484 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004485 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 endif
Enno3146d632024-07-04 19:44:42 +02004487
4488 let dict={}
4489 " save the unnamed register and register 0-9 and a
4490 let dict.a=[getreg('a'), getregtype('a')]
4491 for i in range(0, 9)
4492 let dict[i] = [getreg(i), getregtype(i)]
4493 endfor
4494 let dict.unnamed = [getreg(''), getregtype('')]
4495
Bram Moolenaarc236c162008-07-13 17:41:49 +00004496 let eofname= filestart + b:netrw_cpf + 1
4497 if eofname <= col("$")
4498 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004499 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004500 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004502 endif
Enno3146d632024-07-04 19:44:42 +02004503
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004505 call s:RestoreRegister(dict)
4506
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004507" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004509" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 endif
4511
4512 " symlinks are indicated by a trailing "@". Remove it before further processing.
4513 let dirname= substitute(dirname,"@$","","")
4514
4515 " executables are indicated by a trailing "*". Remove it before further processing.
4516 let dirname= substitute(dirname,"\*$","","")
4517
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004518 let &l:sol= keepsol
4519
Bram Moolenaar446cb832008-06-24 21:56:24 +00004520" call Dret("s:NetrwGetWord <".dirname.">")
4521 return dirname
4522endfun
4523
4524" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004525" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4526" g:netrw_bufsettings will be used after the listing is produced.
4527" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004528fun! s:NetrwListSettings(islocal)
4529" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004530" 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 +00004531 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004532" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4533 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4534 setl bt=nofile nobl ma nonu nowrap noro nornu
4535 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004537 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004539" call Dredir("ls!","s:NetrwListSettings")
4540" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004541 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004542 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004544 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004546 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004548" 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 +00004549" call Dret("s:NetrwListSettings")
4550endfun
4551
4552" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004553" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554" islocal=0: remote browsing
4555" =1: local browsing
4556fun! s:NetrwListStyle(islocal)
4557" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004558
Bram Moolenaar97d62492012-11-15 21:28:22 +01004559 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560 let fname = s:NetrwGetWord()
4561 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004562 let svpos = winsaveview()
4563" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004564 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004565" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4566" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4567" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004568
Bram Moolenaar85850f32019-07-19 22:05:51 +02004569 " repoint t:netrw_lexbufnr if appropriate
4570 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4571" call Decho("set repointlexbufnr to true!")
4572 let repointlexbufnr= 1
4573 endif
4574
Bram Moolenaar446cb832008-06-24 21:56:24 +00004575 if w:netrw_liststyle == s:THINLIST
4576 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004577" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4579
4580 elseif w:netrw_liststyle == s:LONGLIST
4581 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004582" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4584
4585 elseif w:netrw_liststyle == s:WIDELIST
4586 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004587" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004588 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4589
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004590 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004591" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4593
4594 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004595 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596 let g:netrw_liststyle = s:THINLIST
4597 let w:netrw_liststyle = g:netrw_liststyle
4598 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4599 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004600 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602
4603 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4605 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004606 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004608 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" 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 +00004610
4611 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004613 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004614 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004615
Bram Moolenaar85850f32019-07-19 22:05:51 +02004616 " repoint t:netrw_lexbufnr if appropriate
4617 if exists("repointlexbufnr")
4618 let t:netrw_lexbufnr= bufnr("%")
4619" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4620 endif
4621
Bram Moolenaar13600302014-05-22 18:26:40 +02004622 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004623" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4624 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004625 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004626
4627" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4628endfun
4629
4630" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004631" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4632fun! s:NetrwBannerCtrl(islocal)
4633" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4634
Bram Moolenaar97d62492012-11-15 21:28:22 +01004635 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004636 " toggle the banner (enable/suppress)
4637 let g:netrw_banner= !g:netrw_banner
4638
4639 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004640 let svpos= winsaveview()
4641" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004642 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4643
4644 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004645 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4646 let fname= s:NetrwGetWord()
4647 sil NetrwKeepj $
4648 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4649" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4650 if result <= 0 && exists("w:netrw_bannercnt")
4651 exe "NetrwKeepj ".w:netrw_bannercnt
4652 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004653 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004654 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004655" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4656endfun
4657
4658" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004659" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4660"
4661" No bang: enters files/directories into Netrw's bookmark system
4662" No argument and in netrw buffer:
4663" if there are marked files: bookmark marked files
4664" otherwise : bookmark file/directory under cursor
4665" No argument and not in netrw buffer: bookmarks current open file
4666" Has arguments: globs them individually and bookmarks them
4667"
4668" With bang: deletes files/directories from Netrw's bookmark system
4669fun! s:NetrwBookmark(del,...)
4670" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4671 if a:0 == 0
4672 if &ft == "netrw"
4673 let curbufnr = bufnr("%")
4674
4675 if exists("s:netrwmarkfilelist_{curbufnr}")
4676 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004677" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004678 let svpos = winsaveview()
4679" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004680 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004681 for fname in s:netrwmarkfilelist_{curbufnr}
4682 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4683 endfor
4684 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4685 call s:NetrwUnmarkList(curbufnr,curdir)
4686 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004687" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4688 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004689 else
4690 let fname= s:NetrwGetWord()
4691 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4692 endif
4693
4694 else
4695 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004696" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697 let fname= expand("%")
4698 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4699 endif
4700
4701 else
4702 " bookmark specified files
4703 " attempts to infer if working remote or local
4704 " by deciding if the current file begins with an url
4705 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004706 let islocal= expand("%") !~ '^\a\{3,}://'
4707" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004708 let i = 1
4709 while i <= a:0
4710 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004711 if v:version > 704 || (v:version == 704 && has("patch656"))
4712 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004714 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004716 else
4717 let mbfiles= [a:{i}]
4718 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004720 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004721" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4723 endfor
4724 let i= i + 1
4725 endwhile
4726 endif
4727
4728 " update the menu
4729 call s:NetrwBookmarkMenu()
4730
4731" call Dret("s:NetrwBookmark")
4732endfun
4733
4734" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004735" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4736" .2.[cnt] for bookmarks, and
4737" .3.[cnt] for history
4738" (see s:NetrwMenu())
4739fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004740 if !exists("s:netrw_menucnt")
4741 return
4742 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004743" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004744
4745 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004746 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004747 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004748" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004749 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4750 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004751 endif
4752 if !exists("s:netrw_initbookhist")
4753 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 endif
4755
4756 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004757 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004758 let cnt= 1
4759 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004760" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004761 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004762
4763 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004764 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004765
4766 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 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 +01004768 let cnt= cnt + 1
4769 endfor
4770
4771 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004772
4773 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004774 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004775 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004776 let first = 1
4777 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004780 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 if exists("g:netrw_dirhist_{cnt}")
4782 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004783" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4785 endif
4786 let first = 0
4787 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4788 if cnt < 0
4789 let cnt= cnt + g:netrw_dirhistmax
4790 endif
4791 endwhile
4792 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004793
Bram Moolenaar9964e462007-05-05 17:54:07 +00004794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004795" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796endfun
4797
4798" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004799" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4800" directory and a new directory name. Also, if the
4801" "new directory name" is actually a file,
4802" NetrwBrowseChgDir() edits the file.
4803fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004804" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." win#".winnr()." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004805" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004806
Bram Moolenaar97d62492012-11-15 21:28:22 +01004807 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004808 if !exists("b:netrw_curdir")
4809 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4810 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004811 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004812" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4813" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004814" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004816 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004818" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004820 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004822 call s:SavePosn(s:netrw_posn)
4823 NetrwKeepj call s:NetrwOptionsSave("s:")
4824 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004825 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004826 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004827 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004828 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004829 endif
4830 let newdir = a:newdir
4831 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004832 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004833" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004834" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004835" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004836
4837 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004838" call Decho('(s:NetrwBrowseChgDir) ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004839 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004840" call Decho("win#".winnr()." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004841 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004842 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" call Decho("#1: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004844 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" call Decho("#2: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004846 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004847 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004848 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004849 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" 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 +01004851 endif
4852 endif
4853" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004854" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004855 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004856
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 " set up o/s-dependent directory recognition pattern
4858 if has("amiga")
4859 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004860 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861 let dirpat= '[\/]$'
4862 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004863" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864
4865 if dirname !~ dirpat
4866 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004867 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 endif
4871
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004872" call Decho("[newdir<".newdir."> ".((newdir =~ dirpat)? "=~" : "!~")." dirpat<".dirpat.">] && [islocal=".a:islocal."] && [newdir is ".(isdirectory(s:NetrwFile(newdir))? "" : "not ")."a directory]",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004873 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004874 " ------------------------------
4875 " NetrwBrowseChgDir: edit a file {{{3
4876 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004877" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004878
Bram Moolenaar97d62492012-11-15 21:28:22 +01004879 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004880 let s:rexposn_{bufnr("%")}= winsaveview()
4881" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004882" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4883" call Decho("edit-a-file: w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')." w:netrw_treedict:".(exists("w:netrw_treedict")? "exists" : 'n/a')." newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004884
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004886" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4887" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004888" let newdir = s:NetrwTreePath(s:netrw_treetop)
4889" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004890 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004891 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4892" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4893 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 if dirname =~ '/$'
4895 let dirname= dirname.newdir
4896 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004897 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004899" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4900" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004902" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004904 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004907" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004908 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004910" call Decho("edit-a-file: (a:0=".a:0."<1) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004911 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004912 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004914" " call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr()." g:netrw_chgwin=".g:netrw_chgwin",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004915 if type(g:netrw_browse_split) == 3
4916 " open file in server
4917 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004918" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004919 call s:NetrwServerEdit(a:islocal,dirname)
4920" call Dret("s:NetrwBrowseChgDir")
4921 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004922
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004923 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004924 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004925" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004926 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4927 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004928 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004929 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004930 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004931 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004932
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004934 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004935" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004936 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4937 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004938 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004939 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004940 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004941 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004942
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004944 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004946 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004947 if !exists("b:netrw_curdir")
4948 let b:netrw_curdir= getcwd()
4949 endif
4950 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004951
Bram Moolenaar446cb832008-06-24 21:56:24 +00004952 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004953 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004954" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004956 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004958 return
4959 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004960 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004961
Bram Moolenaar9964e462007-05-05 17:54:07 +00004962 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004964" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004965 call s:NetrwMenu(0)
4966 " optional change to window
4967 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004968" call Decho("edit-a-file: changing window to #".g:netrw_chgwin.": (due to g:netrw_chgwin)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004969 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004970 " if g:netrw_chgwin is set to one more than the last window, then
4971 " vertically split the last window to make that window available.
4972 let curwin= winnr()
4973 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4974 vs
4975 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004976 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004977 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004978 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004979 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004980 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004981
Bram Moolenaar9964e462007-05-05 17:54:07 +00004982 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004983
Bram Moolenaar446cb832008-06-24 21:56:24 +00004984 " the point where netrw actually edits the (local) file
4985 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004986 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004987 if !&mod
4988 " if e the new file would fail due to &mod, then don't change any of the flags
4989 let dolockout= 1
4990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004991 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004992" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004993 " some like c-^ to return to the last edited file
4994 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004995 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4996 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004997 call s:NetrwEditFile("e","",dirname)
4998" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004999 " COMBAK -- cuc cul related
5000 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005001 if &hidden || &bufhidden == "hide"
5002 " file came from vim's hidden storage. Don't "restore" options with it.
5003 let dorestore= 0
5004 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005005 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005006" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005007 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005008
5009 " handle g:Netrw_funcref -- call external-to-netrw functions
5010 " This code will handle g:Netrw_funcref as an individual function reference
5011 " or as a list of function references. It will ignore anything that's not
5012 " a function reference. See :help Funcref for information about function references.
5013 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005014" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005015 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005017 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005018 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005020 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005021 if type(Fncref) == 2
5022 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005023 endif
5024 endfor
5025 endif
5026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005027 endif
5028
5029 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005030 " ----------------------------------------------------
5031 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5032 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005033" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005034 let dirname = newdir
5035 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005036 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005037 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005038
5039 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005040 " ---------------------------------------------
5041 " NetrwBrowseChgDir: refresh the directory list {{{3
5042 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005043" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005044 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005045 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005046
5047 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005048 " --------------------------------------
5049 " NetrwBrowseChgDir: go up one directory {{{3
5050 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005051" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005052
5053 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5054 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005055" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5056" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005057 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005058 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005059 endif
5060
5061 if has("amiga")
5062 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005063" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005064 if a:islocal
5065 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5066 let dirname= substitute(dirname,'/$','','')
5067 else
5068 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5069 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005070" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005071
Nir Lichtman1e34b952024-05-08 19:19:34 +02005072 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005073 " windows
5074 if a:islocal
5075 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5076 if dirname == ""
5077 let dirname= '/'
5078 endif
5079 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005080 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005081 endif
5082 if dirname =~ '^\a:$'
5083 let dirname= dirname.'/'
5084 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005085" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005086
Bram Moolenaar446cb832008-06-24 21:56:24 +00005087 else
5088 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005089" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005090 if a:islocal
5091 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5092 if dirname == ""
5093 let dirname= '/'
5094 endif
5095 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005098" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005099 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005100 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005101 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102
5103 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005104 " --------------------------------------
5105 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5106 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005107" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005108 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5109" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005110 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5113 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005114 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005115 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005117 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005118 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005119" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120
5121 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005122" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005124" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 let haskey= 1
5126 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005127" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 endif
5129
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005130 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005131" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133 if has_key(w:netrw_treedict,treedir."/")
5134 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005135" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 let haskey = 1
5137 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005138" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 endif
5140 endif
5141
5142 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005143" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144 if !haskey && treedir =~ '/$'
5145 let treedir= substitute(treedir,'/$','','')
5146 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005147" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 let haskey = 1
5149 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005150" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005151 endif
5152 endif
5153
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 if haskey
5156 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005159" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5160" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005161 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 else
5163 " go down one directory
5164 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005165" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5166" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005168 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005169" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005170 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171
5172 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005173 " ----------------------------------------
5174 " NetrwBrowseChgDir: Go down one directory {{{3
5175 " ----------------------------------------
5176 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005177" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005178 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005179 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005180 endif
5181
Bram Moolenaar97d62492012-11-15 21:28:22 +01005182 " --------------------------------------
5183 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5184 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005185 if dorestore
5186 " dorestore is zero'd when a local file was hidden or bufhidden;
5187 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005188" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005189 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005190" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005191" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005192 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005193 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005195 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5197" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005198 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005200 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5202" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005203 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005205 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005206 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005207 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005208 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005209
Bram Moolenaar446cb832008-06-24 21:56:24 +00005210" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5211 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005212endfun
5213
5214" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005215" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5216" for thin, long, and wide: cursor placed just after banner
5217" for tree, keeps cursor on current filename
5218fun! s:NetrwBrowseUpDir(islocal)
5219" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005220 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5221 " this test needed because occasionally this function seems to be incorrectly called
5222 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005223 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005224 " directories.
5225" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5226 return
5227 endif
5228
Bram Moolenaara6878372014-03-22 21:02:50 +01005229 norm! 0
5230 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005231" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005232 let curline= getline(".")
5233 let swwline= winline() - 1
5234 if exists("w:netrw_treetop")
5235 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005236 elseif exists("b:netrw_curdir")
5237 let w:netrw_treetop= b:netrw_curdir
5238 else
5239 let w:netrw_treetop= getcwd()
5240 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005242 let curfile = getline(".")
5243 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005244 if a:islocal
5245 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5246 else
5247 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5248 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005249" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5250" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5251 if w:netrw_treetop == '/'
5252 keepj call search('^\M'.curfile,"w")
5253 elseif curfile == '../'
5254 keepj call search('^\M'.curfile,"wb")
5255 else
5256" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5257 while 1
5258 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5259 let treepath= s:NetrwTreePath(w:netrw_treetop)
5260" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5261 if treepath == curpath
5262 break
5263 endif
5264 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005265 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005266
Bram Moolenaara6878372014-03-22 21:02:50 +01005267 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005268" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005269 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005270 if exists("b:netrw_curdir")
5271 let curdir= b:netrw_curdir
5272 else
5273 let curdir= expand(getcwd())
5274 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005275 if a:islocal
5276 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5277 else
5278 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5279 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005280 call s:RestorePosn(s:netrw_posn)
5281 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005282 let curdir= '\<'. escape(curdir, '~'). '/'
5283 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005284 endif
5285" call Dret("s:NetrwBrowseUpDir")
5286endfun
5287
5288" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005289" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005290" given filename; typically this means given their extension.
5291" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005292fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005293 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005294" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005295
Bram Moolenaar91359012019-11-30 17:57:03 +01005296 if a:remote == 0 && isdirectory(a:fname)
5297 " if its really just a local directory, then do a "gf" instead
5298" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
Bram Moolenaar29634562020-01-09 21:46:04 +01005299" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5300 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005301" call Dret("netrw#BrowseX")
5302 return
5303 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5304 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5305" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5306" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5307" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5308" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5309 norm! gf
5310" call Dret("netrw#BrowseX")
5311 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005312 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005313" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005314
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005315 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5316 let remote = a:remote
5317 else
5318 let remote = 0
5319 endif
5320
Bram Moolenaar97d62492012-11-15 21:28:22 +01005321 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005322 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005323" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005324
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005325 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5326 let awkeep = &aw
5327 set noaw
5328
Bram Moolenaar5c736222010-01-06 20:54:52 +01005329 " special core dump handler
5330 if a:fname =~ '/core\(\.\d\+\)\=$'
5331 if exists("g:Netrw_corehandler")
5332 if type(g:Netrw_corehandler) == 2
5333 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005334" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005335 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005336 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005337 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005338" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005339 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005340 if type(Fncref) == 2
5341 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 endif
5343 endfor
5344 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005345" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005346 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005347 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005348 let &aw= awkeep
5349" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005350 return
5351 endif
5352 endif
5353
Bram Moolenaar446cb832008-06-24 21:56:24 +00005354 " set up the filename
5355 " (lower case the extension, make a local copy of a remote file)
5356 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005357 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005358 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005359 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005360 if exten =~ "[\\/]"
5361 let exten= ""
5362 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005363" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005364
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005365 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005366 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005367" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005368 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005369 call netrw#NetRead(3,a:fname)
5370 " attempt to rename tempfile
5371 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005372 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005373" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5374" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005375 if s:netrw_tmpfile != newname && newname != ""
5376 if rename(s:netrw_tmpfile,newname) == 0
5377 " renaming succeeded
5378" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5379 let fname= newname
5380 else
5381 " renaming failed
5382" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5383 let fname= s:netrw_tmpfile
5384 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005385 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005386 let fname= s:netrw_tmpfile
5387 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005388 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005389" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005390 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005391 " special ~ handler for local
5392 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005393" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5394 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005395 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005396 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005397" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5398" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005399
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005400 " set up redirection (avoids browser messages)
5401 " by default, g:netrw_suppress_gx_mesg is true
5402 if g:netrw_suppress_gx_mesg
5403 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005404 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005405 let redir= substitute(&srr,"%s","nul","")
5406 else
5407 let redir= substitute(&srr,"%s","/dev/null","")
5408 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005409 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005410 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005411 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005412 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005413 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005414 else
5415 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005417" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005419 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005421" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 if g:netrw_browsex_viewer =~ '\s'
5423 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5424 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5425 let oviewer = ''
5426 let cnt = 1
5427 while !executable(viewer) && viewer != oviewer
5428 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5429 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5430 let cnt = cnt + 1
5431 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005432" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005433 endwhile
5434 else
5435 let viewer = g:netrw_browsex_viewer
5436 let viewopt = ""
5437 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005438" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005439 endif
5440
5441 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005442" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005444" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 let ret= netrwFileHandlers#Invoke(exten,fname)
5446
5447 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005448" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005449 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450 let ret= v:shell_error
5451
Nir Lichtman1e34b952024-05-08 19:19:34 +02005452 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005453" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005454 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005455 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005456 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005457 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005458 else
5459 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5460 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005461 let ret= v:shell_error
5462
Bram Moolenaar97d62492012-11-15 21:28:22 +01005463 elseif has("win32unix")
5464 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005465" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005466 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005467" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005468 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005469 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005470" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005471 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005472 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005474 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005475 else
5476 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5477 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005478 let ret= v:shell_error
5479
Bram Moolenaar85850f32019-07-19 22:05:51 +02005480 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005481" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5482 if a:fname =~ '^https\=://'
5483 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5484 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005485" call Decho("fname<".fname.">")
5486" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5488
5489 else
5490 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5491 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005492 let ret= v:shell_error
5493
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005494 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5495" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5496 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5497 let ret= v:shell_error
5498
5499 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5500" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5501 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5502 let ret= v:shell_error
5503
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005504 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005505" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005506 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005507 let ret= v:shell_error
5508
5509 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005510" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005511 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005512 let ret= v:shell_error
5513
5514 else
5515 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005516" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005517 let ret= netrwFileHandlers#Invoke(exten,fname)
5518 endif
5519
5520 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5521 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005522" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523 let ret= netrwFileHandlers#Invoke(exten,fname)
5524 endif
5525
Bram Moolenaarc236c162008-07-13 17:41:49 +00005526 " restoring redraw! after external file handlers
5527 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005528
5529 " cleanup: remove temporary file,
5530 " delete current buffer if success with handler,
5531 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005532 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005533 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005534" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005535"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005536" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005537" endif
5538
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005539 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005540 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005542 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005544 if use_ctrlo
5545 exe "sil! NetrwKeepj norm! \<c-o>"
5546 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005548" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005549 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005550 let @@ = ykeep
5551 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005552
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005553" call Dret("netrw#BrowseX")
5554endfun
5555
5556" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005557" netrw#GX: gets word under cursor for gx support {{{2
5558" See also: netrw#BrowseXVis
5559" netrw#BrowseX
5560fun! netrw#GX()
5561" call Dfunc("netrw#GX()")
5562 if &ft == "netrw"
5563 let fname= s:NetrwGetWord()
5564 else
5565 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5566 endif
5567" call Dret("netrw#GX <".fname.">")
5568 return fname
5569endfun
5570
5571" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005572" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5573fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005574 let dict={}
5575 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005576 norm! gv"ay
5577 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005578 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005579 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005580endfun
5581
5582" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005583" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5584" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5585" to become an unlisted buffer, so in that case don't bwipe it.
5586fun! s:NetrwBufRename(newname)
5587" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5588" call Dredir("ls!","s:NetrwBufRename (before rename)")
5589 let oldbufname= bufname(bufnr("%"))
5590" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5591
5592 if oldbufname != a:newname
5593" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5594 let b:junk= 1
5595" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5596 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005597" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005598 let oldbufnr= bufnr(oldbufname)
5599" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5600" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5601 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5602" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5603 exe "bwipe! ".oldbufnr
5604" else " Decho
5605" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005606" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5607" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5608" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005609 endif
5610" call Dredir("ls!","s:NetrwBufRename (after rename)")
5611" else " Decho
5612" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5613 endif
5614
5615" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5616endfun
5617
5618" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005619" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005620fun! netrw#CheckIfRemote(...)
5621" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5622 if a:0 > 0
5623 let curfile= a:1
5624 else
5625 let curfile= expand("%")
5626 endif
5627" call Decho("curfile<".curfile.">")
5628 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005629" call Dret("netrw#CheckIfRemote 1")
5630 return 1
5631 else
5632" call Dret("netrw#CheckIfRemote 0")
5633 return 0
5634 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005635endfun
5636
5637" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005638" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5639fun! s:NetrwChgPerm(islocal,curdir)
5640" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005641 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005642 call inputsave()
5643 let newperm= input("Enter new permission: ")
5644 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005645 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5646 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5647" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005648 call system(chgperm)
5649 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005650 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005651 endif
5652 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005653 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005655 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005656" call Dret("s:NetrwChgPerm")
5657endfun
5658
5659" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005660" s:CheckIfKde: checks if kdeinit is running {{{2
5661" Returns 0: kdeinit not running
5662" 1: kdeinit is running
5663fun! s:CheckIfKde()
5664" call Dfunc("s:CheckIfKde()")
5665 " seems kde systems often have gnome-open due to dependencies, even though
5666 " gnome-open's subsidiary display tools are largely absent. Kde systems
5667 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5668 if !exists("s:haskdeinit")
5669 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005670 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005671 if v:shell_error
5672 let s:haskdeinit = 0
5673 endif
5674 else
5675 let s:haskdeinit= 0
5676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005677" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005678 endif
5679
5680" call Dret("s:CheckIfKde ".s:haskdeinit)
5681 return s:haskdeinit
5682endfun
5683
5684" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005685" s:NetrwClearExplore: clear explore variables (if any) {{{2
5686fun! s:NetrwClearExplore()
5687" call Dfunc("s:NetrwClearExplore()")
5688 2match none
5689 if exists("s:explore_match") |unlet s:explore_match |endif
5690 if exists("s:explore_indx") |unlet s:explore_indx |endif
5691 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5692 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5693 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5694 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5695 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5696 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5697 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5698" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005699" call Dret("s:NetrwClearExplore")
5700endfun
5701
5702" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005703" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5704fun! s:NetrwEditBuf(bufnum)
5705" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5706 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5707" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5708 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5709 else
5710" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005711 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005712 endif
5713" call Dret("s:NetrwEditBuf")
5714endfun
5715
5716" ---------------------------------------------------------------------
5717" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5718" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5719fun! s:NetrwEditFile(cmd,opt,fname)
5720" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5721 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5722" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5723 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5724 else
5725" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005726 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5727 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5728 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005729 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5730 endif
5731" call Dret("s:NetrwEditFile")
5732endfun
5733
5734" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005735" s:NetrwExploreListUniq: {{{2
5736fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005737" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005738
5739 " this assumes that the list is already sorted
5740 let newexplist= []
5741 for member in a:explist
5742 if !exists("uniqmember") || member != uniqmember
5743 let uniqmember = member
5744 let newexplist = newexplist + [ member ]
5745 endif
5746 endfor
5747
Bram Moolenaar15146672011-10-20 22:22:38 +02005748" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005749 return newexplist
5750endfun
5751
5752" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005753" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5754fun! s:NetrwForceChgDir(islocal,newdir)
5755" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005756 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005757 if a:newdir !~ '/$'
5758 " ok, looks like force is needed to get directory-style treatment
5759 if a:newdir =~ '@$'
5760 let newdir= substitute(a:newdir,'@$','/','')
5761 elseif a:newdir =~ '[*=|\\]$'
5762 let newdir= substitute(a:newdir,'.$','/','')
5763 else
5764 let newdir= a:newdir.'/'
5765 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005766" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005767 else
5768 " should already be getting treatment as a directory
5769 let newdir= a:newdir
5770 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005771 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005772 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005773 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005774" call Dret("s:NetrwForceChgDir")
5775endfun
5776
5777" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005778" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005779" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5780" expr : this is the expression to follow the directory. Will use s:ComposePath()
5781" pare =1: remove the current directory from the resulting glob() filelist
5782" =0: leave the current directory in the resulting glob() filelist
5783fun! s:NetrwGlob(direntry,expr,pare)
5784" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005785 if netrw#CheckIfRemote()
5786 keepalt 1sp
5787 keepalt enew
5788 let keep_liststyle = w:netrw_liststyle
5789 let w:netrw_liststyle = s:THINLIST
5790 if s:NetrwRemoteListing() == 0
5791 keepj keepalt %s@/@@
5792 let filelist= getline(1,$)
5793 q!
5794 else
5795 " remote listing error -- leave treedict unchanged
5796 let filelist= w:netrw_treedict[a:direntry]
5797 endif
5798 let w:netrw_liststyle= keep_liststyle
5799 else
Christian Brabandt14879472024-06-13 21:25:35 +02005800 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005801 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005802 " escape [ so it is not detected as wildcard character, see :h wildcard
5803 let path= substitute(path, '[', '[[]', 'g')
5804 endif
5805 if v:version > 704 || (v:version == 704 && has("patch656"))
5806 let filelist= glob(path,0,1,1)
5807 else
5808 let filelist= glob(path,0,1)
5809 endif
5810 if a:pare
5811 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5812 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005813 endif
5814" call Dret("s:NetrwGlob ".string(filelist))
5815 return filelist
5816endfun
5817
5818" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005819" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5820fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005821" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005822 if a:newfile =~ '[/@*=|\\]$'
5823 let newfile= substitute(a:newfile,'.$','','')
5824 else
5825 let newfile= a:newfile
5826 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005827 if a:islocal
5828 call s:NetrwBrowseChgDir(a:islocal,newfile)
5829 else
5830 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5831 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005832" call Dret("s:NetrwForceFile")
5833endfun
5834
5835" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005836" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5837" and switches the hiding mode. The actual hiding is done by
5838" s:NetrwListHide().
5839" g:netrw_hide= 0: show all
5840" 1: show not-hidden files
5841" 2: show hidden files only
5842fun! s:NetrwHide(islocal)
5843" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005844 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005845 let svpos= winsaveview()
5846" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005847
5848 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005849" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5850" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005851
5852 " hide the files in the markfile list
5853 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005854" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005855 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5856 " remove fname from hiding list
5857 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5858 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5859 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005860" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005861 else
5862 " append fname to hiding list
5863 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5864 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5865 else
5866 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5867 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005868" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 endif
5870 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005871 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872 let g:netrw_hide= 1
5873
5874 else
5875
5876 " switch between show-all/show-not-hidden/show-hidden
5877 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005878 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005880 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005881 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882" call Dret("NetrwHide")
5883 return
5884 endif
5885 endif
5886
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005887 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005888" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5889 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005890 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005892endfun
5893
5894" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005895" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5896fun! s:NetrwHideEdit(islocal)
5897" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5898
5899 let ykeep= @@
5900 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005901 let svpos= winsaveview()
5902" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005903
5904 " get new hiding list from user
5905 call inputsave()
5906 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5907 call inputrestore()
5908 let g:netrw_list_hide= newhide
5909" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5910
5911 " refresh the listing
5912 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5913
5914 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005915" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5916 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005917 let @@= ykeep
5918
5919" call Dret("NetrwHideEdit")
5920endfun
5921
5922" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005923" s:NetrwHidden: invoked by "gh" {{{2
5924fun! s:NetrwHidden(islocal)
5925" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005926 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005928 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005929" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930
5931 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005932 " remove .file pattern from hiding list
5933" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005934 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005935 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005936" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5938 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5941 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005942 if g:netrw_list_hide =~ '^,'
5943 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5944 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945
5946 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005947 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005948" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5949 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005950 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005951" call Dret("s:NetrwHidden")
5952endfun
5953
5954" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005955" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5956fun! s:NetrwHome()
5957 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005958 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005959 else
5960 " go to vim plugin home
5961 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005962 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005963 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005964 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005965 let home= basehome."/.vim"
5966 break
5967 endif
5968 endfor
5969 if home == ""
5970 " just pick the first directory
5971 let home= substitute(&rtp,',.*$','','')
5972 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005973 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005974 let home= substitute(home,'/','\\','g')
5975 endif
5976 endif
5977 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005978 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005979" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005980 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005981" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005982 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005983 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005985 call mkdir(home)
5986 endif
5987 endif
5988 let g:netrw_home= home
5989 return home
5990endfun
5991
5992" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005993" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5994fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005995 if exists("s:netrwdrag")
5996 return
5997 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005998 if &ft != "netrw"
5999 return
6000 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006001" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006002
Bram Moolenaar97d62492012-11-15 21:28:22 +01006003 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006004 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006005 while getchar(0) != 0
6006 "clear the input stream
6007 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006008 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006009 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006010 let mouse_lnum = v:mouse_lnum
6011 let wlastline = line('w$')
6012 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006013" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6014" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006015 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6016 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006017 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6019 return
6020 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006021 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006022 " 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 +01006023 " without this test when its disabled.
6024 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006025" call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006026 if v:mouse_col > virtcol('.')
6027 let @@= ykeep
6028" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6029 return
6030 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006031
Bram Moolenaar446cb832008-06-24 21:56:24 +00006032 if a:islocal
6033 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006034 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006035 endif
6036 else
6037 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006038 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006039 endif
6040 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006041 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006042" call Dret("s:NetrwLeftmouse")
6043endfun
6044
6045" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006046" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6047fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006048 if &ft != "netrw"
6049 return
6050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006051" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6052 call s:NetrwMarkFileTgt(a:islocal)
6053" call Dret("s:NetrwCLeftmouse")
6054endfun
6055
6056" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006057" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6058" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006059" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060" a:islocal=2 : <c-r> used, remote
6061" a:islocal=3 : <c-r> used, local
6062fun! s:NetrwServerEdit(islocal,fname)
6063" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6064 let islocal = a:islocal%2 " =0: remote =1: local
6065 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006068 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006069 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006070 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006073 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006074 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6075 unlet s:netrw_browse_split_{winnr()}
6076 endif
6077 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6078" call Dret("s:NetrwServerEdit")
6079 return
6080 endif
6081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006082" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006083 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085
6086 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088 let srvrname = g:netrw_browse_split[0]
6089 let tabnum = g:netrw_browse_split[1]
6090 let winnum = g:netrw_browse_split[2]
6091
6092 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006093" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006094
6095 if !ctrlr
6096 " user must have closed the server window and the user did not use <c-r>, but
6097 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006100 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101 endif
6102 let g:netrw_browse_split= 0
6103 if exists("s:netrw_browse_split_".winnr())
6104 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6105 endif
6106 call s:NetrwBrowseChgDir(islocal,a:fname)
6107" call Dret("s:NetrwServerEdit")
6108 return
6109
6110 elseif has("win32") && executable("start")
6111 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006112" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006113 call system("start gvim --servername ".srvrname)
6114
6115 else
6116 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118 call system("gvim --servername ".srvrname)
6119 endif
6120 endif
6121
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006122" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006123 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6124 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126
6127 else
6128
6129 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6130
6131 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006132" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006133 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006134 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006135 endif
6136 let g:netrw_browse_split= 0
6137 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6138" call Dret("s:NetrwServerEdit")
6139 return
6140
6141 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006142" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006143 if has("win32") && executable("start")
6144 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 call system("start gvim --servername ".g:netrw_servername)
6147 else
6148 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006149" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006150 call system("gvim --servername ".g:netrw_servername)
6151 endif
6152 endif
6153 endif
6154
6155 while 1
6156 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006157" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6158 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159 break
6160 catch /^Vim\%((\a\+)\)\=:E241/
6161 sleep 200m
6162 endtry
6163 endwhile
6164
6165 if exists("g:netrw_browse_split")
6166 if type(g:netrw_browse_split) != 3
6167 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6168 endif
6169 unlet g:netrw_browse_split
6170 endif
6171 let g:netrw_browse_split= [g:netrw_servername,1,1]
6172 endif
6173
6174 else
6175 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6176 endif
6177
6178" call Dret("s:NetrwServerEdit")
6179endfun
6180
6181" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006182" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6183fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006184 if &ft != "netrw"
6185 return
6186 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006187" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006188
Bram Moolenaar8d043172014-01-23 14:24:41 +01006189 let s:ngw= s:NetrwGetWord()
6190 call s:NetrwMarkFile(a:islocal,s:ngw)
6191
6192" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006193endfun
6194
6195" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006196" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6197" Used to mark multiple files.
6198fun! s:NetrwSLeftdrag(islocal)
6199" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6200 if !exists("s:netrwdrag")
6201 let s:netrwdrag = winnr()
6202 if a:islocal
6203 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006204 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006205 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006206 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006207 endif
6208 let ngw = s:NetrwGetWord()
6209 if !exists("s:ngw") || s:ngw != ngw
6210 call s:NetrwMarkFile(a:islocal,ngw)
6211 endif
6212 let s:ngw= ngw
6213" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6214endfun
6215
6216" ---------------------------------------------------------------------
6217" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6218fun! s:NetrwSLeftrelease(islocal)
6219" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6220 if exists("s:netrwdrag")
6221 nunmap <s-leftrelease>
6222 let ngw = s:NetrwGetWord()
6223 if !exists("s:ngw") || s:ngw != ngw
6224 call s:NetrwMarkFile(a:islocal,ngw)
6225 endif
6226 if exists("s:ngw")
6227 unlet s:ngw
6228 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006229 unlet s:netrwdrag
6230 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006231" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006232endfun
6233
6234" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006235" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6236" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006237fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006238" 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 +02006239" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006240 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006241
6242 " 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 +02006243 " How-it-works: take the hiding command, convert it into a range.
6244 " Duplicate characters don't matter.
6245 " Remove all such characters from the '/~@#...890' string.
6246 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006247" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006248 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006249 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006250" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251
6252 while listhide != ""
6253 if listhide =~ ','
6254 let hide = substitute(listhide,',.*$','','e')
6255 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6256 else
6257 let hide = listhide
6258 let listhide = ""
6259 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006260" 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 +01006261 if g:netrw_sort_by =~ '^[ts]'
6262 if hide =~ '^\^'
6263" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6264 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6265 elseif hide =~ '^\\(\^'
6266 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6267 endif
6268" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270
6271 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006272" 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 +00006273 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006274" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006275 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006276 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006277" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006280" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006282
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006284 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006286 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006287" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006288 endif
6289
Bram Moolenaaradc21822011-04-01 18:03:16 +02006290 " remove any blank lines that have somehow remained.
6291 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006292 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006293
Bram Moolenaar97d62492012-11-15 21:28:22 +01006294 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006295" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296endfun
6297
6298" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006300" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006301fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006302" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303
Bram Moolenaar97d62492012-11-15 21:28:22 +01006304 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 " get name of new directory from user. A bare <CR> will skip.
6306 " if its currently a directory, also request will be skipped, but with
6307 " a message.
6308 call inputsave()
6309 let newdirname= input("Please give directory name: ")
6310 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006311" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312
6313 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006314 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006315" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006316 return
6317 endif
6318
6319 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006320" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006321
6322 " Local mkdir:
6323 " sanity checks
6324 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006325" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6326 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006328 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006330 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006331" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 return
6333 endif
6334 if s:FileReadable(fullnewdir)
6335 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006336 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006338 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006339" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 return
6341 endif
6342
6343 " requested new local directory is neither a pre-existing file or
6344 " directory, so make it!
6345 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006346 if has("unix")
6347 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6348 else
6349 call mkdir(fullnewdir,"p")
6350 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006351 else
6352 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006353 if s:NetrwLcd(b:netrw_curdir)
6354" call Dret("s:NetrwMakeDir : lcd failure")
6355 return
6356 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006357" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006358 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006359 if v:shell_error != 0
6360 let @@= ykeep
6361 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006362" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006363 return
6364 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006366" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006367 if s:NetrwLcd(netrw_origdir)
6368" call Dret("s:NetrwBrowse : lcd failure")
6369 return
6370 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006371 endif
6372 endif
6373
6374 if v:shell_error == 0
6375 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006376" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006377 let svpos= winsaveview()
6378" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006379 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006380" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6381 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382 elseif !exists("g:netrw_quiet")
6383 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6384 endif
6385" redraw!
6386
6387 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006388 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006389" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006390 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6391 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 if v:shell_error == 0
6394 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006395 let svpos= winsaveview()
6396" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006397 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006398" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6399 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006400 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006401 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006402 endif
6403" redraw!
6404
6405 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006406 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006407 let svpos= winsaveview()
6408" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006409" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006411" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006412 let remotepath= b:netrw_fname
6413 else
6414 let remotepath= ""
6415 endif
6416 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006417 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006418" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6419 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006420
Bram Moolenaar446cb832008-06-24 21:56:24 +00006421 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006422 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006423 let svpos= winsaveview()
6424" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006427" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006428 let remotepath= b:netrw_fname
6429 else
6430 let remotepath= ""
6431 endif
6432 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006433 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006434" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6435 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006436 endif
6437
Bram Moolenaar97d62492012-11-15 21:28:22 +01006438 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006439" call Dret("s:NetrwMakeDir")
6440endfun
6441
6442" ---------------------------------------------------------------------
6443" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6444fun! s:TreeSqueezeDir(islocal)
6445" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6446 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6447 " its a tree-listing style
6448 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006449 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006450 let depth = strchars(substitute(curdepth,' ','','g'))
6451 let srch = -1
6452" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6453" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006454" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006455" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6456 if depth >= 2
6457 NetrwKeepj norm! 0
6458 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6459 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6460" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6461" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6462 elseif depth == 1
6463 NetrwKeepj norm! 0
6464 let treedepthchr= substitute(s:treedepthstring,' ','','')
6465 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6466" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6467 endif
6468 if srch > 0
6469" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6470 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6471 exe srch
6472 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006473 endif
6474" call Dret("s:TreeSqueezeDir")
6475endfun
6476
6477" ---------------------------------------------------------------------
6478" s:NetrwMaps: {{{2
6479fun! s:NetrwMaps(islocal)
6480" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6481
Bram Moolenaar85850f32019-07-19 22:05:51 +02006482 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006483 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006484" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006485 if !hasmapto("<Plug>NetrwReturn")
6486 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6489 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6492 endif
6493 endif
6494 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006495" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 endif
6497
Bram Moolenaar85850f32019-07-19 22:05:51 +02006498 " generate default <Plug> maps {{{3
6499 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006500 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006501 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6502 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6503 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6504 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6505 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6506 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6507 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6508 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6509 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6510 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6511" ---------------------------------------------------------------------
6512" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6513" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6514" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6515" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6516" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6517" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6518" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6519" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6520" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6521" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6522" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6523" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6524" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6525" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6526" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6527" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6528" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6529" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6530" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6531" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6532" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6533" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6534" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6535" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6536" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6537" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6538" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6539" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6540" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6541" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6542" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6543" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6544" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6545" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6546" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6547" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6548" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6549" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6550" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6551" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6552" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6553" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6554" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6555" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6556" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6557" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6558" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6559
Bram Moolenaara6878372014-03-22 21:02:50 +01006560 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006561" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006562 " local normal-mode maps {{{3
6563 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6564 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6565 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6566 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6574" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006575 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6576 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6577 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006578 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006579 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006580 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6581 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6582 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6583 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006584 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6585 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6586 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6588 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6589 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6590 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6591 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006598 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006599 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6602 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6603 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006604 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006606 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6607 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6609 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6610 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006613 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006617 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6618 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6619 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006620 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6621 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006622
6623 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006624 if !hasmapto('<Plug>NetrwHideEdit')
6625 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006626 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006627 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006628 if !hasmapto('<Plug>NetrwRefresh')
6629 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006630 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006631 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006632 if s:didstarstar || !mapcheck("<s-down>","n")
6633 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006634 endif
6635 if s:didstarstar || !mapcheck("<s-up>","n")
6636 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006637 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006638 if !hasmapto('<Plug>NetrwTreeSqueeze')
6639 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006640 endif
6641 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6643 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006644 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6645 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6646 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6647 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6648 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6649 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6650 imap <buffer> <leftmouse> <Plug>ILeftmouse
6651 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006652 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6653 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6654 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6655 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6656 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006657 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006658 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6659 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006660 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6662 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6663 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6664 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6665 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6666 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6667 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6669
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670 " support user-specified maps
6671 call netrw#UserMaps(1)
6672
Bram Moolenaar85850f32019-07-19 22:05:51 +02006673 else
6674 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006675" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006676 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006677 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6678 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6679 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6680 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6688" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006689 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6690 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6691 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6692 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6693 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6694 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6695 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6696 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006698 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006699 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6701 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6702 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6703 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6704 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006710 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006711 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6715 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6716 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006717 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6720 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006721 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006722 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6723 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006724 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006725 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006726 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6729 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6730 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6731 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6732 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6733 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6734 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006735 if !hasmapto('<Plug>NetrwHideEdit')
6736 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006737 endif
6738 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6739 if !hasmapto('<Plug>NetrwRefresh')
6740 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006741 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006742 if !hasmapto('<Plug>NetrwTreeSqueeze')
6743 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006744 endif
6745 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006746
6747 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006748 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006749
6750 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6751 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006753 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006755 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006757 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006758 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006759 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006761 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6763 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6764 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006767 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6768 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006769 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6771 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6772 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6773 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6775 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006777 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006778
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006779 " support user-specified maps
6780 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006781 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006782
6783" call Dret("s:NetrwMaps")
6784endfun
6785
6786" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006787" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006788" If -buffer, the command is only available from within netrw buffers
6789" Otherwise, the command is available from any window, so long as netrw
6790" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006791fun! s:NetrwCommands(islocal)
6792" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6793
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006794 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6795 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006796 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 +01006797 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006798 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006799 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006800 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006801 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006802 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006803
6804" call Dret("s:NetrwCommands")
6805endfun
6806
6807" ---------------------------------------------------------------------
6808" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6809" glob()ing only works with local files
6810fun! s:NetrwMarkFiles(islocal,...)
6811" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812 let curdir = s:NetrwGetCurdir(a:islocal)
6813 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006814 while i <= a:0
6815 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006816 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006817 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006819 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006820 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006821 else
6822 let mffiles= [a:{i}]
6823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006824" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006825 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 call s:NetrwMarkFile(a:islocal,mffile)
6828 endfor
6829 let i= i + 1
6830 endwhile
6831" call Dret("s:NetrwMarkFiles")
6832endfun
6833
6834" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006835" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006836fun! s:NetrwMarkTarget(...)
6837" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6838 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839 let curdir = s:NetrwGetCurdir(1)
6840 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006841 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6843 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006846 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006847 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6848 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006849 let svpos = winsaveview()
6850" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006851 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006852" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6853 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006854" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855endfun
6856
6857" ---------------------------------------------------------------------
6858" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6859" mark and unmark files. If a markfile list exists,
6860" then the rename and delete functions will use it instead
6861" of whatever may happen to be under the cursor at that
6862" moment. When the mouse and gui are available,
6863" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006864"
6865" Creates two lists
6866" s:netrwmarkfilelist -- holds complete paths to all marked files
6867" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6868"
6869" Creates a marked file match string
6870" s:netrwmarfilemtch_# -- used with 2match to display marked files
6871"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006872" Creates a buffer version of islocal
6873" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006874fun! s:NetrwMarkFile(islocal,fname)
6875" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006876" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006877
6878 " sanity check
6879 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006880" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006881 return
6882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006883 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006884
Bram Moolenaar97d62492012-11-15 21:28:22 +01006885 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006886 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006887 if a:fname =~ '^\a'
6888 let leader= '\<'
6889 else
6890 let leader= ''
6891 endif
6892 if a:fname =~ '\a$'
6893 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6894 else
6895 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6896 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006897
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006899 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006900" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6901" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6902" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006903 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904
6905 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006909 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910
6911 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006912 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6915 if s:netrwmarkfilelist_{curbufnr} == []
6916 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006917" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 call s:NetrwUnmarkList(curbufnr,curdir)
6919 else
6920 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006921" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006923 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 for fname in s:netrwmarkfilelist_{curbufnr}
6925 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006926 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006928 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006929 endif
6930 let first= 0
6931 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933 endif
6934 endif
6935
6936 else
6937 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006938" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006939
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006940" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006942 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6943" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944
6945 " build initial markfile matching pattern
6946 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006947 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006949 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 endif
6953
6954 " handle global markfilelist
6955 if exists("s:netrwmarkfilelist")
6956 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6957 if index(s:netrwmarkfilelist,dname) == -1
6958 " append new filename to global markfilelist
6959 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006960" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 else
6962 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6964" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006968" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 unlet s:netrwmarkfilelist
6970 endif
6971 endif
6972 else
6973 " initialize new global-directory markfilelist
6974 let s:netrwmarkfilelist= []
6975 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006976" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977 endif
6978
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006980 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6981 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6982" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6983 if exists("g:did_drchip_netrwlist_syntax")
6984 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6985 endif
6986 else
6987" " call Decho("2match none",'~'.expand("<slnum>"))
6988 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006990 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006991 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006992" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6993" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist")."> (buf#".curbufnr."list)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006994endfun
6995
6996" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006997" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6998" mA: move the argument list to marked file list (tomflist=1)
6999" Uses the global marked file list
7000fun! s:NetrwMarkFileArgList(islocal,tomflist)
7001" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7002
7003 let svpos = winsaveview()
7004" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7005 let curdir = s:NetrwGetCurdir(a:islocal)
7006 let curbufnr = bufnr("%")
7007
7008 if a:tomflist
7009 " mA: move argument list to marked file list
7010 while argc()
7011 let fname= argv(0)
7012" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7013 exe "argdel ".fnameescape(fname)
7014 call s:NetrwMarkFile(a:islocal,fname)
7015 endwhile
7016
7017 else
7018 " ma: move marked file list to argument list
7019 if exists("s:netrwmarkfilelist")
7020
7021 " for every filename in the marked list
7022 for fname in s:netrwmarkfilelist
7023" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7024 exe "argadd ".fnameescape(fname)
7025 endfor " for every file in the marked list
7026
7027 " unmark list and refresh
7028 call s:NetrwUnmarkList(curbufnr,curdir)
7029 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7030" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7031 NetrwKeepj call winrestview(svpos)
7032 endif
7033 endif
7034
7035" call Dret("s:NetrwMarkFileArgList")
7036endfun
7037
7038" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007039" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7040" compress/decompress files using the programs
7041" in g:netrw_compress and g:netrw_uncompress,
7042" using g:netrw_compress_suffix to know which to
7043" do. By default:
7044" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007045" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007046fun! s:NetrwMarkFileCompress(islocal)
7047" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007048 let svpos = winsaveview()
7049" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007050 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007051 let curbufnr = bufnr("%")
7052
Bram Moolenaarff034192013-04-24 18:51:19 +02007053 " sanity check
7054 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007055 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007056" call Dret("s:NetrwMarkFileCompress")
7057 return
7058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007059" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007060
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007062
7063 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007065 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007066" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007067 if exists("g:netrw_decompress['".sfx."']")
7068 " fname has a suffix indicating that its compressed; apply associated decompression routine
7069 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007070" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007071 let exe= netrw#WinPath(exe)
7072 if a:islocal
7073 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007074 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007076 call system(exe." ".fname)
7077 if v:shell_error
7078 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007079 endif
7080 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007081 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7082 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007083 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084
Bram Moolenaarff034192013-04-24 18:51:19 +02007085 endif
7086 unlet sfx
7087
Bram Moolenaar446cb832008-06-24 21:56:24 +00007088 if exists("exe")
7089 unlet exe
7090 elseif a:islocal
7091 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007093 if v:shell_error
7094 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7095 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096 else
7097 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007098 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007100 endfor " for every file in the marked list
7101
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007103 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007104" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7105 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007106 endif
7107" call Dret("s:NetrwMarkFileCompress")
7108endfun
7109
7110" ---------------------------------------------------------------------
7111" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7112" If no marked files, then set up directory as the
7113" target. Currently does not support copying entire
7114" directories. Uses the local-buffer marked file list.
7115" Returns 1=success (used by NetrwMarkFileMove())
7116" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007117fun! s:NetrwMarkFileCopy(islocal,...)
7118" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7119
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007120 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007121 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007122 if b:netrw_curdir !~ '/$'
7123 if !exists("b:netrw_curdir")
7124 let b:netrw_curdir= curdir
7125 endif
7126 let b:netrw_curdir= b:netrw_curdir."/"
7127 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128
Bram Moolenaarff034192013-04-24 18:51:19 +02007129 " sanity check
7130 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007131 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007132" call Dret("s:NetrwMarkFileCopy")
7133 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007135" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007136
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007138 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139" call Dret("s:NetrwMarkFileCopy 0")
7140 return 0
7141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007142" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007143
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007144 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007145 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007146" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007147 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007148 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7149" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7150 return
7151 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007152
7153 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007154 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007155 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7156 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007157" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007158 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007159 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7160 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007163 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007164 let oldname = a:1
7165 else
7166 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007167" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007168 let s:recursive= 1
7169 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7170 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7171 if ret == 0
7172 break
7173 endif
7174 endfor
7175 unlet s:recursive
7176 call s:NetrwUnmarkList(curbufnr,curdir)
7177" call Dret("s:NetrwMarkFileCopy ".ret)
7178 return ret
7179 endif
7180
7181 call inputsave()
7182 let newname= input("Copy ".oldname." to : ",oldname,"file")
7183 call inputrestore()
7184 if newname == ""
7185" call Dret("s:NetrwMarkFileCopy 0")
7186 return 0
7187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007188 let args= s:ShellEscape(oldname)
7189 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007190 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7192 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007193 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007194 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007195 let args= substitute(args,'/','\\','g')
7196 let tgt = substitute(tgt, '/','\\','g')
7197 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007198 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7199 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7200 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7201 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7202" call Decho("args <".args.">",'~'.expand("<slnum>"))
7203" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204 if isdirectory(s:NetrwFile(args))
7205" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007208 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7210 " contents to a target. One must append the source directory name to the target to get xcopy to
7211 " do the right thing.
7212 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007213" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007214 endif
7215 else
7216 let copycmd= g:netrw_localcopycmd
7217 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007218 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007219 let copycmd = substitute(copycmd,'\s.*$','','')
7220 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 let copycmd = netrw#WinPath(copycmd).copycmdargs
7222 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007223 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007225" call Decho("args <".args.">",'~'.expand("<slnum>"))
7226" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7227" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7228" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007229 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007230 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007231 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007232 call netrw#ErrorMsg(s:ERROR,"copy failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",101)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007233 else
7234 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7235 endif
7236" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007237 return 0
7238 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007239
7240 elseif a:islocal && !s:netrwmftgt_islocal
7241 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007242" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007243 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244
7245 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007246 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007247" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007248 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007249
7250 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007251 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007252" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253 let curdir = getcwd()
7254 let tmpdir = s:GetTempfile("")
7255 if tmpdir !~ '/'
7256 let tmpdir= curdir."/".tmpdir
7257 endif
7258 if exists("*mkdir")
7259 call mkdir(tmpdir)
7260 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007261 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007262 if v:shell_error != 0
7263 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007264" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 return
7266 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007268 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007269 if s:NetrwLcd(tmpdir)
7270" call Dret("s:NetrwMarkFileCopy : lcd failure")
7271 return
7272 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007273 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007274 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007275 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276 if getcwd() == tmpdir
7277 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007280 if s:NetrwLcd(curdir)
7281" call Dret("s:NetrwMarkFileCopy : lcd failure")
7282 return
7283 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007284 if delete(tmpdir,"d")
7285 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007286 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007287 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007288 if s:NetrwLcd(curdir)
7289" call Dret("s:NetrwMarkFileCopy : lcd failure")
7290 return
7291 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 endif
7293 endif
7294 endif
7295
7296 " -------
7297 " cleanup
7298 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007299" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007300 " remove markings from local buffer
7301 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007302" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7303" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7304" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7305" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7306" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7307" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7308 if exists("s:recursive")
7309" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7310 else
7311" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007312 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007313 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007314 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007315 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316 else
7317 " refresh local and targets for fast browsing
7318 if !exists("s:recursive")
7319 " remove markings from local buffer
7320" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7321 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7322 endif
7323
7324 " refresh buffers
7325 if s:netrwmftgt_islocal
7326" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7327 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7328 endif
7329 if a:islocal && s:netrwmftgt != curdir
7330" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7331 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7332 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007333 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007334
Bram Moolenaar446cb832008-06-24 21:56:24 +00007335" call Dret("s:NetrwMarkFileCopy 1")
7336 return 1
7337endfun
7338
7339" ---------------------------------------------------------------------
7340" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7341" invoke vim's diff mode on the marked files.
7342" Either two or three files can be so handled.
7343" Uses the global marked file list.
7344fun! s:NetrwMarkFileDiff(islocal)
7345" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7346 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007347
Bram Moolenaarff034192013-04-24 18:51:19 +02007348 " sanity check
7349 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007350 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007351" call Dret("s:NetrwMarkFileDiff")
7352 return
7353 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354 let curdir= s:NetrwGetCurdir(a:islocal)
7355" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007356
Bram Moolenaara6878372014-03-22 21:02:50 +01007357 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007358 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007359 for fname in s:netrwmarkfilelist
7360 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007362" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007363 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 diffthis
7365 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007366 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007367" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007368 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007369 diffthis
7370 else
7371 break
7372 endif
7373 endfor
7374 call s:NetrwUnmarkList(curbufnr,curdir)
7375 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007376
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377" call Dret("s:NetrwMarkFileDiff")
7378endfun
7379
7380" ---------------------------------------------------------------------
7381" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7382" Uses global markfilelist
7383fun! s:NetrwMarkFileEdit(islocal)
7384" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7385
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007388
7389 " sanity check
7390 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007391 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007392" call Dret("s:NetrwMarkFileEdit")
7393 return
7394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007395" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007396
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 if exists("s:netrwmarkfilelist_{curbufnr}")
7398 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007399 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 " unmark markedfile list
7401" call s:NetrwUnmarkList(curbufnr,curdir)
7402 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007403" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007404 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007406 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007407
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408" call Dret("s:NetrwMarkFileEdit")
7409endfun
7410
7411" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007412" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007413fun! s:NetrwMarkFileQFEL(islocal,qfel)
7414" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7415 call s:NetrwUnmarkAll()
7416 let curbufnr= bufnr("%")
7417
7418 if !empty(a:qfel)
7419 for entry in a:qfel
7420 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007422 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007424 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7425 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7426 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7427 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007429 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7430 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 endif
7433 endfor
7434 echo "(use me to edit marked files)"
7435 else
7436 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7437 endif
7438
7439" call Dret("s:NetrwMarkFileQFEL")
7440endfun
7441
7442" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007443" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7444" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7445" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7446fun! s:NetrwMarkFileExe(islocal,enbloc)
7447" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007448 let svpos = winsaveview()
7449" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007450 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 let curbufnr = bufnr("%")
7452
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007453 if a:enbloc == 0
7454 " individually apply command to files, one at a time
7455 " sanity check
7456 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7457 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7458" call Dret("s:NetrwMarkFileExe")
7459 return
7460 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007461" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007462
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 if exists("s:netrwmarkfilelist_{curbufnr}")
7464 " get the command
7465 call inputsave()
7466 let cmd= input("Enter command: ","","file")
7467 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007468" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007469 if cmd == ""
7470" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7471 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007472 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007473
7474 " apply command to marked files, individually. Substitute: filename -> %
7475 " If no %, then append a space and the filename to the command
7476 for fname in s:netrwmarkfilelist_{curbufnr}
7477 if a:islocal
7478 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007479 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007480 endif
7481 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007482 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 endif
7484 if cmd =~ '%'
7485 let xcmd= substitute(cmd,'%',fname,'g')
7486 else
7487 let xcmd= cmd.' '.fname
7488 endif
7489 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007490" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 let ret= system(xcmd)
7492 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 let ret= s:RemoteSystem(xcmd)
7495 endif
7496 if v:shell_error < 0
7497 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7498 break
7499 else
7500 echo ret
7501 endif
7502 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503
7504 " unmark marked file list
7505 call s:NetrwUnmarkList(curbufnr,curdir)
7506
7507 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007509" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7510 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007512 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007513 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007514
7515 else " apply command to global list of files, en bloc
7516
7517 call inputsave()
7518 let cmd= input("Enter command: ","","file")
7519 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 if cmd == ""
7522" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7523 return
7524 endif
7525 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007526 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007527 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007528 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007529 endif
7530 if a:islocal
7531 call system(cmd)
7532 if v:shell_error < 0
7533 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7534 endif
7535 else
7536 let ret= s:RemoteSystem(cmd)
7537 endif
7538 call s:NetrwUnmarkAll()
7539
7540 " refresh the listing
7541 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007542" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7543 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007544
7545 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007546
Bram Moolenaar446cb832008-06-24 21:56:24 +00007547" call Dret("s:NetrwMarkFileExe")
7548endfun
7549
7550" ---------------------------------------------------------------------
7551" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7552" as the marked file(s) (toggles suffix presence)
7553" Uses the local marked file list.
7554fun! s:NetrwMarkHideSfx(islocal)
7555" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007556 let svpos = winsaveview()
7557" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007558 let curbufnr = bufnr("%")
7559
7560 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7561 if exists("s:netrwmarkfilelist_{curbufnr}")
7562
7563 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007564" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007565 " construct suffix pattern
7566 if fname =~ '\.'
7567 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7568 else
7569 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7570 endif
7571 " determine if its in the hiding list or not
7572 let inhidelist= 0
7573 if g:netrw_list_hide != ""
7574 let itemnum = 0
7575 let hidelist= split(g:netrw_list_hide,',')
7576 for hidepat in hidelist
7577 if sfxpat == hidepat
7578 let inhidelist= 1
7579 break
7580 endif
7581 let itemnum= itemnum + 1
7582 endfor
7583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007584" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007585 if inhidelist
7586 " remove sfxpat from list
7587 call remove(hidelist,itemnum)
7588 let g:netrw_list_hide= join(hidelist,",")
7589 elseif g:netrw_list_hide != ""
7590 " append sfxpat to non-empty list
7591 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7592 else
7593 " set hiding list to sfxpat
7594 let g:netrw_list_hide= sfxpat
7595 endif
7596 endfor
7597
7598 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007599 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007600" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7601 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007603 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007604 endif
7605
7606" call Dret("s:NetrwMarkHideSfx")
7607endfun
7608
7609" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007610" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007611" Uses the local marked-file list.
7612fun! s:NetrwMarkFileVimCmd(islocal)
7613" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007614 let svpos = winsaveview()
7615" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007616 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007617 let curbufnr = bufnr("%")
7618
Bram Moolenaarff034192013-04-24 18:51:19 +02007619 " sanity check
7620 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007621 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007622" call Dret("s:NetrwMarkFileVimCmd")
7623 return
7624 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007625" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007626
Bram Moolenaar15146672011-10-20 22:22:38 +02007627 if exists("s:netrwmarkfilelist_{curbufnr}")
7628 " get the command
7629 call inputsave()
7630 let cmd= input("Enter vim command: ","","file")
7631 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007633 if cmd == ""
7634" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7635 return
7636 endif
7637
7638 " apply command to marked files. Substitute: filename -> %
7639 " If no %, then append a space and the filename to the command
7640 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007642 if a:islocal
7643 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007644 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007645" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007646 exe cmd
7647 exe "sil! keepalt wq!"
7648 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007649" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007650 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007651 endif
7652 endfor
7653
7654 " unmark marked file list
7655 call s:NetrwUnmarkList(curbufnr,curdir)
7656
7657 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007658 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007659" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7660 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007661 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007662 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007664
Bram Moolenaar15146672011-10-20 22:22:38 +02007665" call Dret("s:NetrwMarkFileVimCmd")
7666endfun
7667
7668" ---------------------------------------------------------------------
7669" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7670" as the marked file(s) (toggles suffix presence)
7671" Uses the local marked file list.
7672fun! s:NetrwMarkHideSfx(islocal)
7673" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007674 let svpos = winsaveview()
7675" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007676 let curbufnr = bufnr("%")
7677
7678 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7679 if exists("s:netrwmarkfilelist_{curbufnr}")
7680
7681 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007682" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007683 " construct suffix pattern
7684 if fname =~ '\.'
7685 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7686 else
7687 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7688 endif
7689 " determine if its in the hiding list or not
7690 let inhidelist= 0
7691 if g:netrw_list_hide != ""
7692 let itemnum = 0
7693 let hidelist= split(g:netrw_list_hide,',')
7694 for hidepat in hidelist
7695 if sfxpat == hidepat
7696 let inhidelist= 1
7697 break
7698 endif
7699 let itemnum= itemnum + 1
7700 endfor
7701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007702" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007703 if inhidelist
7704 " remove sfxpat from list
7705 call remove(hidelist,itemnum)
7706 let g:netrw_list_hide= join(hidelist,",")
7707 elseif g:netrw_list_hide != ""
7708 " append sfxpat to non-empty list
7709 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7710 else
7711 " set hiding list to sfxpat
7712 let g:netrw_list_hide= sfxpat
7713 endif
7714 endfor
7715
7716 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007717 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007718" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7719 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007720 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007721 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007722 endif
7723
7724" call Dret("s:NetrwMarkHideSfx")
7725endfun
7726
7727" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007728" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7729" Uses the global markfilelist
7730fun! s:NetrwMarkFileGrep(islocal)
7731" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007732 let svpos = winsaveview()
7733" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007734 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007736
7737 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007738" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007739 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007740" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007742 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007743" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007744 let netrwmarkfilelist= "*"
7745 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007748" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007749 call inputsave()
7750 let pat= input("Enter pattern: ","")
7751 call inputrestore()
7752 let patbang = ""
7753 if pat =~ '^!'
7754 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007756 endif
7757 if pat =~ '^\i'
7758 let pat = escape(pat,'/')
7759 let pat = '/'.pat.'/'
7760 else
7761 let nonisi = pat[0]
7762 endif
7763
7764 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007766 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007767 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007768 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007769 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007770" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7771 return
7772 endtry
7773 echo "(use :cn, :cp to navigate, :Rex to return)"
7774
7775 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007776" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7777 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007778
7779 if exists("nonisi")
7780 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007781" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007782 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007783 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007785 endif
7786
7787" call Dret("s:NetrwMarkFileGrep")
7788endfun
7789
7790" ---------------------------------------------------------------------
7791" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7792" uses the global marked file list
7793" s:netrwmfloc= 0: target directory is remote
7794" = 1: target directory is local
7795fun! s:NetrwMarkFileMove(islocal)
7796" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007798 let curbufnr = bufnr("%")
7799
7800 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007801 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007802 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007803" call Dret("s:NetrwMarkFileMove")
7804 return
7805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007807
Bram Moolenaar446cb832008-06-24 21:56:24 +00007808 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007809 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007810" call Dret("s:NetrwMarkFileCopy 0")
7811 return 0
7812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007813" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814
7815 if a:islocal && s:netrwmftgt_islocal
7816 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007817" call Decho("move from local to local",'~'.expand("<slnum>"))
7818" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007819 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007820 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7821" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7822 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007824 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007826 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007829 if g:netrw_localmovecmd =~ '\s'
7830 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7831 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7832 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007834 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007835 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 endif
7838 else
7839 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007840" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007841 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007842 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007843 if g:netrw_keepdir
7844 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7845 let fname= b:netrw_curdir."/".fname
7846 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007847 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007848 let fname= substitute(fname,'/','\\','g')
7849 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007851 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007852 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007855 else
7856 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7857 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007858 break
7859 endif
7860 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007861
7862 elseif a:islocal && !s:netrwmftgt_islocal
7863 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864" call Decho("move from local to remote",'~'.expand("<slnum>"))
7865" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007866 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007867 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007868" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 for fname in mflist
7870 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7871 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7872 endfor
7873 unlet mflist
7874
7875 elseif !a:islocal && s:netrwmftgt_islocal
7876 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" call Decho("move from remote to local",'~'.expand("<slnum>"))
7878" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007879 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007880 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007881" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 for fname in mflist
7883 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7884 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7885 endfor
7886 unlet mflist
7887
7888 elseif !a:islocal && !s:netrwmftgt_islocal
7889 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007890" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7891" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007893 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 for fname in mflist
7896 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7897 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7898 endfor
7899 unlet mflist
7900 endif
7901
7902 " -------
7903 " cleanup
7904 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007905" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007906
7907 " remove markings from local buffer
7908 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7909
7910 " refresh buffers
7911 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007912" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007913 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007914 endif
7915 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007916" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007917 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007918 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007919 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007920" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007921 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007922 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924" call Dret("s:NetrwMarkFileMove")
7925endfun
7926
7927" ---------------------------------------------------------------------
7928" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7929" using the hardcopy command. Local marked-file list only.
7930fun! s:NetrwMarkFilePrint(islocal)
7931" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7932 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007933
7934 " sanity check
7935 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007936 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007937" call Dret("s:NetrwMarkFilePrint")
7938 return
7939 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007940" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7941 let curdir= s:NetrwGetCurdir(a:islocal)
7942
Bram Moolenaar446cb832008-06-24 21:56:24 +00007943 if exists("s:netrwmarkfilelist_{curbufnr}")
7944 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007945 call s:NetrwUnmarkList(curbufnr,curdir)
7946 for fname in netrwmarkfilelist
7947 if a:islocal
7948 if g:netrw_keepdir
7949 let fname= s:ComposePath(curdir,fname)
7950 endif
7951 else
7952 let fname= curdir.fname
7953 endif
7954 1split
7955 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007957 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007958" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959 hardcopy
7960 q
7961 endfor
7962 2match none
7963 endif
7964" call Dret("s:NetrwMarkFilePrint")
7965endfun
7966
7967" ---------------------------------------------------------------------
7968" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7969" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007970" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007971fun! s:NetrwMarkFileRegexp(islocal)
7972" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7973
7974 " get the regular expression
7975 call inputsave()
7976 let regexp= input("Enter regexp: ","","file")
7977 call inputrestore()
7978
7979 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007980 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007981" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007982 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007983" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007984 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007985 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007986 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007987 else
7988 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007991" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007992
7993 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007994 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007995 if fname =~ '^'.fnameescape(curdir)
7996" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7997 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7998 else
7999" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8000 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8001 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008002 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008003
8004 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008005" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 " convert displayed listing into a filelist
8008 let eikeep = &ei
8009 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008010 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008011 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008012" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008014 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008015 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008016 sil NetrwKeepj norm! "ap
8017 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008020 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008023 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8029 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008030 call histdel("/",-1)
8031 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 endif
8033 " convert regexp into the more usual glob-style format
8034 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008035" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008037 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038 let filelist= getline(1,line("$"))
8039 q!
8040 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008041 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 endfor
8043 unlet filelist
8044 let @a = areg
8045 let &ei = eikeep
8046 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008047 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048
8049" call Dret("s:NetrwMarkFileRegexp")
8050endfun
8051
8052" ---------------------------------------------------------------------
8053" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8054" Uses the local marked file list.
8055fun! s:NetrwMarkFileSource(islocal)
8056" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8057 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008058
8059 " sanity check
8060 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008062" call Dret("s:NetrwMarkFileSource")
8063 return
8064 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8066 let curdir= s:NetrwGetCurdir(a:islocal)
8067
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 if exists("s:netrwmarkfilelist_{curbufnr}")
8069 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070 call s:NetrwUnmarkList(curbufnr,curdir)
8071 for fname in netrwmarkfilelist
8072 if a:islocal
8073 if g:netrw_keepdir
8074 let fname= s:ComposePath(curdir,fname)
8075 endif
8076 else
8077 let fname= curdir.fname
8078 endif
8079 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008080" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008081 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082 endfor
8083 2match none
8084 endif
8085" call Dret("s:NetrwMarkFileSource")
8086endfun
8087
8088" ---------------------------------------------------------------------
8089" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8090" Uses the global markfilelist
8091fun! s:NetrwMarkFileTag(islocal)
8092" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008093 let svpos = winsaveview()
8094" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008095 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008096 let curbufnr = bufnr("%")
8097
Bram Moolenaarff034192013-04-24 18:51:19 +02008098 " sanity check
8099 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008100 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008101" call Dret("s:NetrwMarkFileTag")
8102 return
8103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008104" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008105
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8108 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 call s:NetrwUnmarkAll()
8110
8111 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008112
8113" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8114 call system(g:netrw_ctags." ".netrwmarkfilelist)
8115 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8117 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008118
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008120 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008121 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 let curdir= b:netrw_curdir
8123 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008124 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008127 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008128 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 wq!
8130 endif
8131 2match none
8132 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008133" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8134 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 endif
8136
8137" call Dret("s:NetrwMarkFileTag")
8138endfun
8139
8140" ---------------------------------------------------------------------
8141" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008143" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008144" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008145" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008147" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8148 let svpos = winsaveview()
8149" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151 let hadtgt = exists("s:netrwmftgt")
8152 if !exists("w:netrw_bannercnt")
8153 let w:netrw_bannercnt= b:netrw_bannercnt
8154 endif
8155
8156 " set up target
8157 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008159 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8160 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008162 unlet s:netrwmftgt s:netrwmftgt_islocal
8163 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008164 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 endif
8166 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008167" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8168 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008169" call Dret("s:NetrwMarkFileTgt : removed target")
8170 return
8171 else
8172 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008173" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008174 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175
8176 else
8177 " get word under cursor.
8178 " * If directory, use it for the target.
8179 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 let curword= s:NetrwGetWord()
8182 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186 elseif !a:islocal && tgtdir =~ '/$'
8187 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 else
8190 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 endif
8193 endif
8194 if a:islocal
8195 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8196 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008198 endif
8199 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8202 endif
8203 let s:netrwmftgt_islocal= a:islocal
8204
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205 " need to do refresh so that the banner will be updated
8206 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008207 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008208" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008209 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008211" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008212 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8214 else
8215 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8216 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008217" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8218 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008220 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008221 endif
8222
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8224" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8226endfun
8227
8228" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008229" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8230fun! s:NetrwGetCurdir(islocal)
8231" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8232
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008233 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008234 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8235" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8236 elseif !exists("b:netrw_curdir")
8237 let b:netrw_curdir= getcwd()
8238" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8239 endif
8240
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008241" call Decho("b:netrw_curdir<".b:netrw_curdir."> ".((b:netrw_curdir !~ '\<\a\{3,}://')? "does not match" : "matches")." url pattern",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008242 if b:netrw_curdir !~ '\<\a\{3,}://'
8243 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245 if g:netrw_keepdir == 0
8246 call s:NetrwLcd(curdir)
8247 endif
8248 endif
8249
8250" call Dret("s:NetrwGetCurdir <".curdir.">")
8251 return b:netrw_curdir
8252endfun
8253
8254" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008255" s:NetrwOpenFile: query user for a filename and open it {{{2
8256fun! s:NetrwOpenFile(islocal)
8257" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008258 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008259 call inputsave()
8260 let fname= input("Enter filename: ")
8261 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008262" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8263
8264 " determine if Lexplore is in use
8265 if exists("t:netrw_lexbufnr")
8266 " check if t:netrw_lexbufnr refers to a netrw window
8267" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8268 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8269 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8270" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8271 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8272 exe "NetrwKeepj e ".fnameescape(fname)
8273 let @@= ykeep
8274" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8275 endif
8276 endif
8277
8278 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008279 if fname !~ '[/\\]'
8280 if exists("b:netrw_curdir")
8281 if exists("g:netrw_quiet")
8282 let netrw_quiet_keep = g:netrw_quiet
8283 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008284 let g:netrw_quiet = 1
8285 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008286 let s:rexposn_{bufnr("%")}= winsaveview()
8287" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008288 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008289 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008290 else
8291 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8292 endif
8293 if exists("netrw_quiet_keep")
8294 let g:netrw_quiet= netrw_quiet_keep
8295 else
8296 unlet g:netrw_quiet
8297 endif
8298 endif
8299 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008300 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008301 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008302 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008303" call Dret("s:NetrwOpenFile")
8304endfun
8305
8306" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008307" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8308" For the mapping to this function be made via
8309" netrwPlugin, you'll need to have had
8310" g:netrw_usetab set to non-zero.
8311fun! netrw#Shrink()
8312" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8313 let curwin = winnr()
8314 let wiwkeep = &wiw
8315 set wiw=1
8316
8317 if &ft == "netrw"
8318 if winwidth(0) > g:netrw_wiw
8319 let t:netrw_winwidth= winwidth(0)
8320 exe "vert resize ".g:netrw_wiw
8321 wincmd l
8322 if winnr() == curwin
8323 wincmd h
8324 endif
8325" call Decho("vert resize 0",'~'.expand("<slnum>"))
8326 else
8327 exe "vert resize ".t:netrw_winwidth
8328" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8329 endif
8330
8331 elseif exists("t:netrw_lexbufnr")
8332 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8333 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8334 let t:netrw_winwidth= winwidth(0)
8335 exe "vert resize ".g:netrw_wiw
8336 wincmd l
8337 if winnr() == curwin
8338 wincmd h
8339 endif
8340" call Decho("vert resize 0",'~'.expand("<slnum>"))
8341 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8342 exe "vert resize ".t:netrw_winwidth
8343" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8344 else
8345 call netrw#Lexplore(0,0)
8346 endif
8347
8348 else
8349 call netrw#Lexplore(0,0)
8350 endif
8351 let wiw= wiwkeep
8352
8353" call Dret("netrw#Shrink")
8354endfun
8355
8356" ---------------------------------------------------------------------
8357" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8358fun! s:NetSortSequence(islocal)
8359" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8360
8361 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008362 let svpos= winsaveview()
8363" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008364 call inputsave()
8365 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8366 call inputrestore()
8367
8368 " refresh the listing
8369 let g:netrw_sort_sequence= newsortseq
8370 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008371" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8372 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008373 let @@= ykeep
8374
8375" call Dret("NetSortSequence")
8376endfun
8377
8378" ---------------------------------------------------------------------
8379" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8380" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008381" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008382fun! s:NetrwUnmarkList(curbufnr,curdir)
8383" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8384
8385 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008386 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8388 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8389 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8390 call remove(s:netrwmarkfilelist,idx) " remove from global list
8391 endfor
8392 if s:netrwmarkfilelist == []
8393 unlet s:netrwmarkfilelist
8394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395
Bram Moolenaar446cb832008-06-24 21:56:24 +00008396 " getting rid of the local marked-file lists is easy
8397 unlet s:netrwmarkfilelist_{a:curbufnr}
8398 endif
8399 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8400 unlet s:netrwmarkfilemtch_{a:curbufnr}
8401 endif
8402 2match none
8403" call Dret("s:NetrwUnmarkList")
8404endfun
8405
8406" ---------------------------------------------------------------------
8407" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8408fun! s:NetrwUnmarkAll()
8409" call Dfunc("s:NetrwUnmarkAll()")
8410 if exists("s:netrwmarkfilelist")
8411 unlet s:netrwmarkfilelist
8412 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008413 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008414 2match none
8415" call Dret("s:NetrwUnmarkAll")
8416endfun
8417
8418" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008419" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420fun! s:NetrwUnmarkAll2()
8421" call Dfunc("s:NetrwUnmarkAll2()")
8422 redir => netrwmarkfilelist_let
8423 let
8424 redir END
8425 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008426 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008427 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8428 for flist in netrwmarkfilelist_list
8429 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8430 unlet s:netrwmarkfilelist_{curbufnr}
8431 unlet s:netrwmarkfilemtch_{curbufnr}
8432 endfor
8433" call Dret("s:NetrwUnmarkAll2")
8434endfun
8435
8436" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008437" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8438"
8439" Marked files are in two types of lists:
8440" s:netrwmarkfilelist -- holds complete paths to all marked files
8441" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8442"
8443" Marked files suitable for use with 2match are in:
8444" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008445fun! s:NetrwUnMarkFile(islocal)
8446" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008447 let svpos = winsaveview()
8448" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449 let curbufnr = bufnr("%")
8450
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008451 " unmark marked file list
8452 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8453 if exists("s:netrwmarkfilelist")
8454" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008456 endif
8457
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008458 let ibuf= 1
8459 while ibuf < bufnr("$")
8460 if exists("s:netrwmarkfilelist_".ibuf)
8461 unlet s:netrwmarkfilelist_{ibuf}
8462 unlet s:netrwmarkfilemtch_{ibuf}
8463 endif
8464 let ibuf = ibuf + 1
8465 endwhile
8466 2match none
8467
Bram Moolenaar446cb832008-06-24 21:56:24 +00008468" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008469"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8470call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471" call Dret("s:NetrwUnMarkFile")
8472endfun
8473
8474" ---------------------------------------------------------------------
8475" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8476fun! s:NetrwMenu(domenu)
8477
8478 if !exists("g:NetrwMenuPriority")
8479 let g:NetrwMenuPriority= 80
8480 endif
8481
Bram Moolenaaradc21822011-04-01 18:03:16 +02008482 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008483" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8484
8485 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008486" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008487 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008488 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8492 if g:netrw_dirhistmax > 0
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8497 else
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8499 endif
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008515 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t'
Bram Moolenaarff034192013-04-24 18:51:19 +02008516 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008552 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>'
Bram Moolenaarff034192013-04-24 18:51:19 +02008553 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008555 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008556 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8557 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558
8559 elseif !a:domenu
8560 let s:netrwcnt = 0
8561 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008562 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563 exe curwin."wincmd w"
8564
8565 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008566" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008567 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008568" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008569 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008570 endif
8571 endif
8572" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008573 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574 endif
8575
8576endfun
8577
8578" ---------------------------------------------------------------------
8579" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8580" Used by the O maps (as <SID>NetrwObtain())
8581fun! s:NetrwObtain(islocal)
8582" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8583
Bram Moolenaar97d62492012-11-15 21:28:22 +01008584 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008586 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008587 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8589 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008590 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008592 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593
8594" call Dret("NetrwObtain")
8595endfun
8596
8597" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8599" If there's only one window, then the window will first be split.
8600" Returns:
8601" choice = 0 : didn't have to choose
8602" choice = 1 : saved modified file in window first
8603" choice = 2 : didn't save modified file, opened window
8604" choice = 3 : cancel open
8605fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008606" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607
Bram Moolenaar97d62492012-11-15 21:28:22 +01008608 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008610 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008611" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612
8613 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008614 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008616" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8617" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8618 let curword = s:NetrwGetWord()
8619 let choice = 0
8620 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8621" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008622 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008623" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008624 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008625" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008626" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008627" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628
Bram Moolenaar8d043172014-01-23 14:24:41 +01008629 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 if lastwinnr == 1
8631 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008632" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008633 " g:netrw_preview=0: preview window shown in a horizontally split window
8634 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008635 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008636 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008637 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008638" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008639 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008641 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008642 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008643" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008644 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008646 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008647" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648
8649 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008650" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008651 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008652" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008653 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008654" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008655 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008656" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008658" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008659" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008660" call Decho("COMBAK#12: mod=".&mod)
8661
8662 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8663 " whoops -- user trying to open file in the Lexplore window.
8664 " Use Lexplore's opening-file window instead.
8665" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8666" exe g:netrw_chgwin."wincmd w"
8667 wincmd p
8668 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8669 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008670
8671 " prevwinnr: the window number of the "prev" window
8672 " prevbufnr: the buffer number of the buffer in the "prev" window
8673 " bnrcnt : the qty of windows open on the "prev" buffer
8674 let prevwinnr = winnr()
8675 let prevbufnr = bufnr("%")
8676 let prevbufname = bufname("%")
8677 let prevmod = &mod
8678 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008679" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008680 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008681" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683
8684 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008685 " and it doesn't appear in any other extant window, then ask the
8686 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008687 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008688" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008689 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008690" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008691 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008693
8694 if bnrcnt == 1 && &hidden == 0
8695 " only one copy of the modified buffer in a window, and
8696 " hidden not set, so overwriting will lose the modified file. Ask first...
8697 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008698" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008699 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008700" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701
8702 if choice == 1
8703 " Yes -- write file & then browse
8704 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008705 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008706 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008707 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008708 exe origwin."wincmd w"
8709 let &ei = eikeep
8710 let @@ = ykeep
8711" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712 return choice
8713 endif
8714
8715 elseif choice == 2
8716 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008717" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008718 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719
8720 else
8721 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723 exe origwin."wincmd w"
8724 let &ei= eikeep
8725 let @@ = ykeep
8726" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008727 return choice
8728 endif
8729 endif
8730 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008731 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008732 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008733" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008734
8735 " restore b:netrw_curdir (window split/enew may have lost it)
8736 let b:netrw_curdir= curdir
8737 if a:islocal < 2
8738 if a:islocal
8739 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8740 else
8741 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8742 endif
8743 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008744 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008745" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008746 return choice
8747endfun
8748
8749" ---------------------------------------------------------------------
8750" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8751" Always assumed to be local -> remote
8752" call s:NetrwUpload(filename, target)
8753" call s:NetrwUpload(filename, target, fromdirectory)
8754fun! s:NetrwUpload(fname,tgt,...)
8755" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8756
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008757 if a:tgt =~ '^\a\{3,}://'
8758 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759 else
8760 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8761 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008762" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008763
8764 if a:0 > 0
8765 let fromdir= a:1
8766 else
8767 let fromdir= getcwd()
8768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
8771 if type(a:fname) == 1
8772 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008773" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008774 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8776 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8777" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 if a:tgt =~ '/$'
8779 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008780" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008781 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008782 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008784 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786 endif
8787 q!
8788
8789 elseif type(a:fname) == 3
8790 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008791" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 let curdir= getcwd()
8793 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008794 if s:NetrwLcd(fromdir)
8795" call Dret("s:NetrwUpload : lcd failure")
8796 return
8797 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008798 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800 if exists("g:netrw_port") && g:netrw_port != ""
8801 let useport= " ".g:netrw_scpport." ".g:netrw_port
8802 else
8803 let useport= ""
8804 endif
8805 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8806 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008808 if s:NetrwLcd(curdir)
8809" call Dret("s:NetrwUpload : lcd failure")
8810 return
8811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812
8813 elseif a:tgt =~ '^ftp:'
8814 call s:NetrwMethod(a:tgt)
8815
8816 if b:netrw_method == 2
8817 " handle uploading a list of files via ftp+.netrc
8818 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008819 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008820" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
8825 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828 endif
8829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832
Bram Moolenaaradc21822011-04-01 18:03:16 +02008833 if tgtdir == ""
8834 let tgtdir= '/'
8835 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008836 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838
8839 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endfor
8843
8844 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008845 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008846 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8848 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008849 endif
8850 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008851 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008852 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8854 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8855 else
8856 bw!|q
8857 endif
8858
8859 elseif b:netrw_method == 3
8860 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8861 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008864 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865
8866 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008867 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008868" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008869 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 endif
8873
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008874 if exists("g:netrw_uid") && g:netrw_uid != ""
8875 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008876 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008878 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008881" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008882 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886 endif
8887
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008888 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008890
8891 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008893" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 endif
8895
8896 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 endif
8900
8901 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 endfor
8905
8906 " perform ftp:
8907 " -i : turns off interactive prompting from ftp
8908 " -n unix : DON'T use <.netrc>, even though it exists
8909 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008910 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008913 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008914 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8916 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008917 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8919 let &debug = debugkeep
8920 let mod = 1
8921 else
8922 bw!|q
8923 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008924 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008925" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008926 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 endif
8928 else
8929 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8930 endif
8931 endif
8932
8933" call Dret("s:NetrwUpload")
8934endfun
8935
8936" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008937" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008938fun! s:NetrwPreview(path) range
8939" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8941" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008942 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943 NetrwKeepj call s:NetrwOptionsSave("s:")
8944 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8945 NetrwKeepj call s:NetrwOptionsSafe(1)
8946 else
8947 NetrwKeepj call s:NetrwOptionsSafe(0)
8948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008951 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008952" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8953 if g:netrw_preview
8954 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008955 let pvhkeep = &pvh
8956 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8957 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008958" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8959 else
8960 " horizontal split
8961 let pvhkeep = &pvh
8962 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8963 let &pvh = winheight(0) - winsz
8964" call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008965 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008966 " g:netrw_preview g:netrw_alto
8967 " 1 : vert 1: top -- preview window is vertically split off and on the left
8968 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8969 " 0 : 1: top -- preview window is horizontally split off and on the top
8970 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8971 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008972 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
Bram Moolenaar85850f32019-07-19 22:05:51 +02008973 " the BufEnter event set up in netrwPlugin.vim
8974" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8975 let eikeep = &ei
8976 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008977 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008978 let &ei= eikeep
8979" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008980 if exists("pvhkeep")
8981 let &pvh= pvhkeep
8982 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008984 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008985 endif
8986 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008989 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008990 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991" call Dret("NetrwPreview")
8992endfun
8993
8994" ---------------------------------------------------------------------
8995" s:NetrwRefresh: {{{2
8996fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008997" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008998 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008999 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009000" call Decho("setl ma noro",'~'.expand("<slnum>"))
9001" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009002 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009003 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9004 if !exists("w:netrw_treetop")
9005 if exists("b:netrw_curdir")
9006 let w:netrw_treetop= b:netrw_curdir
9007 else
9008 let w:netrw_treetop= getcwd()
9009 endif
9010 endif
9011 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9012 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009013
9014 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009015 let screenposn = winsaveview()
9016" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009017
9018" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9019" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9020 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009022 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009023 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009024 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009025 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009026
9027 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009028" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9029 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009030
9031 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009032 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9033 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9034" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9035 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9036 else
9037" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9038 2match none
9039 endif
9040 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041
Bram Moolenaar97d62492012-11-15 21:28:22 +01009042" restore
9043 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009044" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009045endfun
9046
9047" ---------------------------------------------------------------------
9048" s:NetrwRefreshDir: refreshes a directory by name {{{2
9049" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009050" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009052" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053 if g:netrw_fastbrowse == 0
9054 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009055" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009057" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058
9059 if tgtwin > 0
9060 " tgtwin is being displayed, so refresh it
9061 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009062" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009064 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 exe curwin."wincmd w"
9066
9067 elseif bufnr(a:dirname) > 0
9068 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009069" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9070 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 endif
9072
9073 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009074" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009075 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 endif
9077" call Dret("s:NetrwRefreshDir")
9078endfun
9079
9080" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009081" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9082" window number to do its editing in.
9083" Supports [count]C where the count, if present, is used to specify
9084" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009085fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009086" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009088" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009089 if a:1 == "" " :NetrwC win#
9090 let g:netrw_chgwin= winnr()
9091 else " :NetrwC
9092 let g:netrw_chgwin= a:1
9093 endif
9094 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009095 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009096 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009097 let g:netrw_chgwin= winnr()
9098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009099 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009100" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009101endfun
9102
9103" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009104" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9105" What this function does is to compute a priority for the patterns
9106" in the g:netrw_sort_sequence. It applies a substitute to any
9107" "files" that satisfy each pattern, putting the priority / in
9108" front. An "*" pattern handles the default priority.
9109fun! s:NetrwSetSort()
9110" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009111 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112 if w:netrw_liststyle == s:LONGLIST
9113 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9114 else
9115 let seqlist = g:netrw_sort_sequence
9116 endif
9117 " sanity check -- insure that * appears somewhere
9118 if seqlist == ""
9119 let seqlist= '*'
9120 elseif seqlist !~ '\*'
9121 let seqlist= seqlist.',*'
9122 endif
9123 let priority = 1
9124 while seqlist != ""
9125 if seqlist =~ ','
9126 let seq = substitute(seqlist,',.*$','','e')
9127 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9128 else
9129 let seq = seqlist
9130 let seqlist = ""
9131 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009132 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009133 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009135 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009137 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009139" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140
9141 " sanity check
9142 if w:netrw_bannercnt > line("$")
9143 " apparently no files were left after a Hiding pattern was used
9144" call Dret("SetSort : no files left after hiding")
9145 return
9146 endif
9147 if seq == '*'
9148 let starpriority= spriority
9149 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009150 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009151 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 " sometimes multiple sorting patterns will match the same file or directory.
9153 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009154 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9155 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009156 endif
9157 let priority = priority + 1
9158 endwhile
9159 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009160 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9161 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162 endif
9163
9164 " Following line associated with priority -- items that satisfy a priority
9165 " pattern get prefixed by ###/ which permits easy sorting by priority.
9166 " Sometimes files can satisfy multiple priority patterns -- only the latest
9167 " priority pattern needs to be retained. So, at this point, these excess
9168 " priority prefixes need to be removed, but not directories that happen to
9169 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009170 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9171 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009172 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009173
9174" call Dret("SetSort")
9175endfun
9176
Bram Moolenaarff034192013-04-24 18:51:19 +02009177" ---------------------------------------------------------------------
9178" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9179" Implements [count]Tb (bookhist<b>)
9180" [count]Th (bookhist<h>)
9181" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009182fun! s:NetrwSetTgt(islocal,bookhist,choice)
9183" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009184
9185 if a:bookhist == 'b'
9186 " supports choosing a bookmark as a target using a qb-generated list
9187 let choice= a:choice - 1
9188 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009189 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009190 else
9191 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9192 endif
9193
9194 elseif a:bookhist == 'h'
9195 " supports choosing a history stack entry as a target using a qb-generated list
9196 let choice= (a:choice % g:netrw_dirhistmax) + 1
9197 if exists("g:netrw_dirhist_".choice)
9198 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009199 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009200 else
9201 echomsg "Sorry, history#".a:choice." not available!"
9202 endif
9203 endif
9204
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009205 " refresh the display
9206 if !exists("b:netrw_curdir")
9207 let b:netrw_curdir= getcwd()
9208 endif
9209 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9210
Bram Moolenaarff034192013-04-24 18:51:19 +02009211" call Dret("s:NetrwSetTgt")
9212endfun
9213
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009215" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009216fun! s:NetrwSortStyle(islocal)
9217" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009218 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009219 let svpos= winsaveview()
9220" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009222 let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009223 NetrwKeepj norm! 0
9224 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009225" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9226 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009227
9228" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9229endfun
9230
9231" ---------------------------------------------------------------------
9232" s:NetrwSplit: mode {{{2
9233" =0 : net and o
9234" =1 : net and t
9235" =2 : net and v
9236" =3 : local and o
9237" =4 : local and t
9238" =5 : local and v
9239fun! s:NetrwSplit(mode)
9240" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9241
Bram Moolenaar97d62492012-11-15 21:28:22 +01009242 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243 call s:SaveWinVars()
9244
9245 if a:mode == 0
9246 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009247 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009248 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009249" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009250 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009252 NetrwKeepj call s:RestoreWinVars()
9253 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 unlet s:didsplit
9255
9256 elseif a:mode == 1
9257 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009258 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 tabnew
9261 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 NetrwKeepj call s:RestoreWinVars()
9263 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 unlet s:didsplit
9265
9266 elseif a:mode == 2
9267 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009268 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009269 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009270" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009271 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009272 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009273 NetrwKeepj call s:RestoreWinVars()
9274 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 unlet s:didsplit
9276
9277 elseif a:mode == 3
9278 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009279 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009280 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009281" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009282 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009284 NetrwKeepj call s:RestoreWinVars()
9285 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 unlet s:didsplit
9287
9288 elseif a:mode == 4
9289 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009291 let eikeep = &ei
9292 let netrw_winnr = winnr()
9293 let netrw_line = line(".")
9294 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009295 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009296 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009297 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9299 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300 let &ei = eikeep
9301 let netrw_curdir = s:NetrwTreeDir(0)
9302" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009303 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009304 let b:netrw_curdir = netrw_curdir
9305 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009306 NetrwKeepj call s:RestoreWinVars()
9307 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009308 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009309 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009310 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9311 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009312 let &ei= eikeep
9313 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 unlet s:didsplit
9315
9316 elseif a:mode == 5
9317 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009318 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009319 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009320" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009321 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009323 NetrwKeepj call s:RestoreWinVars()
9324 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 unlet s:didsplit
9326
9327 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009328 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009329 endif
9330
Bram Moolenaar97d62492012-11-15 21:28:22 +01009331 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332" call Dret("s:NetrwSplit")
9333endfun
9334
9335" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009336" s:NetrwTgtMenu: {{{2
9337fun! s:NetrwTgtMenu()
9338 if !exists("s:netrw_menucnt")
9339 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009340 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009341" call Dfunc("s:NetrwTgtMenu()")
9342
9343 " the following test assures that gvim is running, has menus available, and has menus enabled.
9344 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9345 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009346" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009347 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9348 endif
9349 if !exists("s:netrw_initbookhist")
9350 call s:NetrwBookHistRead()
9351 endif
9352
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353 " try to cull duplicate entries
9354 let tgtdict={}
9355
Bram Moolenaarff034192013-04-24 18:51:19 +02009356 " target bookmarked places
9357 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009358" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009359 let cnt= 1
9360 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361 if has_key(tgtdict,bmd)
9362 let cnt= cnt + 1
9363 continue
9364 endif
9365 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009366 let ebmd= escape(bmd,g:netrw_menu_escape)
9367 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009369 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt('".bmd."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009370 let cnt= cnt + 1
9371 endfor
9372 endif
9373
9374 " target directory browsing history
9375 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009377 let histcnt = 1
9378 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009379 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 if exists("g:netrw_dirhist_{histcnt}")
9381 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382 if has_key(tgtdict,histentry)
9383 let histcnt = histcnt + 1
9384 continue
9385 endif
9386 let tgtdict[histentry] = histcnt
9387 let ehistentry = escape(histentry,g:netrw_menu_escape)
9388" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009389 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt('".histentry."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009390 endif
9391 let histcnt = histcnt + 1
9392 endwhile
9393 endif
9394 endif
9395" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009396endfun
9397
9398" ---------------------------------------------------------------------
9399" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9400" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009401fun! s:NetrwTreeDir(islocal)
9402" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009403" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009404" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9405" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9406" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009407" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009409 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009410 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009411" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009412 let treedir= s:treedir
9413 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414 unlet s:prevwinopen
9415" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009416 return treedir
9417 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009418 if exists("s:prevwinopen")
9419 unlet s:prevwinopen
9420 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009421" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422
Bram Moolenaar8d043172014-01-23 14:24:41 +01009423 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9424 let b:netrw_curdir= getcwd()
9425 endif
9426 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009428" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009429
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009430 let s:treecurpos= winsaveview()
9431" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009432" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433
9434 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9436" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009437" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009438
9439 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009440 let curline= substitute(getline('.'),"\t -->.*$",'','')
9441 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009443 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9445 elseif curline =~ '@$'
9446" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009447 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009450" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009451 let treedir= ""
9452 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009453" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454
9455 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9457" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009458" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009459 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009462" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9463 sil! NetrwKeepj %d _
9464" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009465 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009466" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009467" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009469" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009472" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009473" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009474
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009475 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9476" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9477" let newdir = w:netrw_treetop.'/'.potentialdir
9478" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9479" let treedir = s:NetrwTreePath(newdir)
9480" let w:netrw_treetop = newdir
9481" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9482" else
9483" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009484 if a:islocal && curline =~ '@$'
9485 if isdirectory(s:NetrwFile(potentialdir))
9486 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9487 let w:netrw_treetop = treedir
9488 endif
9489 else
9490 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9491 let treedir = s:NetrwTreePath(w:netrw_treetop)
9492 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009493 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009494" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009495
9496 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009497 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009498" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009499" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009502 return treedir
9503endfun
9504
9505" ---------------------------------------------------------------------
9506" s:NetrwTreeDisplay: recursive tree display {{{2
9507fun! s:NetrwTreeDisplay(dir,depth)
9508" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9509
9510 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009511 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009512
9513 " install ../ and shortdir
9514 if a:depth == ""
9515 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009518 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009519 if a:dir == w:netrw_treetop
9520 let shortdir= a:dir
9521 else
9522 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9523 endif
9524 call setline(line("$")+1,a:depth.shortdir)
9525 else
9526 let shortdir= substitute(a:dir,'^.*/','','e')
9527 call setline(line("$")+1,a:depth.shortdir.'/')
9528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009529" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530 " append a / to dir if its missing one
9531 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009532
9533 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009534 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536
Bram Moolenaar85850f32019-07-19 22:05:51 +02009537 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9538 if g:netrw_hide == 1
9539 " hide given patterns
9540 let listhide= split(g:netrw_list_hide,',')
9541" call Decho("listhide=".string(listhide))
9542 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009543 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009544 endfor
9545
9546 elseif g:netrw_hide == 2
9547 " show given patterns (only)
9548 let listhide= split(g:netrw_list_hide,',')
9549" call Decho("listhide=".string(listhide))
9550 let entries=[]
9551 for entry in w:netrw_treedict[dir]
9552 for pat in listhide
9553 if entry =~ pat
9554 call add(entries,entry)
9555 break
9556 endif
9557 endfor
9558 endfor
9559 let w:netrw_treedict[dir]= entries
9560 endif
9561 if depth != ""
9562 " always remove "." and ".." entries when there's depth
9563 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9564 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9565 endif
9566
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009567" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009568 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009569 if dir =~ '/$'
9570 let direntry= substitute(dir.entry,'[@/]$','','e')
9571 else
9572 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9573 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009574" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009577 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9580 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9581 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9582" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009583 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009584 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 endif
9588 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009589" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009590
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591" call Dret("NetrwTreeDisplay")
9592endfun
9593
9594" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009595" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9596fun! s:NetrwRefreshTreeDict(dir)
9597" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009598 if !exists("w:netrw_treedict")
9599" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9600 return
9601 endif
9602
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603 for entry in w:netrw_treedict[a:dir]
9604 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9605" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9606
9607 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9608" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9609 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009610 let liststar = s:NetrwGlob(direntry,'*',1)
9611 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009612 let w:netrw_treedict[direntry] = liststar + listdotstar
9613" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9614
9615 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9616" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9617 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009618 let liststar = s:NetrwGlob(direntry.'/','*',1)
9619 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009620 let w:netrw_treedict[direntry]= liststar + listdotstar
9621" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9622
9623 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9624" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9625 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009626 let liststar = s:NetrwGlob(direntry.'/','*',1)
9627 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009628" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9629
9630 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009631" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009632 endif
9633 endfor
9634" call Dret("s:NetrwRefreshTreeDict")
9635endfun
9636
9637" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009638" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009639" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009640fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009641 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009642" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009643" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9644" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
9645" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009646
9647 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009648 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009649" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009650 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009651 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009654" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009655 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009656 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 if exists("w:netrw_treetop")
9660 let s:netrw_treetop= w:netrw_treetop
9661 else
9662 let w:netrw_treetop= getcwd()
9663 let s:netrw_treetop= w:netrw_treetop
9664 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667 " insure that we have a treedict, albeit empty
9668" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 let w:netrw_treedict= {}
9670 endif
9671
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009672 " update the dictionary for the current directory
9673" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009674" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009678 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679
9680 " if past banner, record word
9681 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9682 let fname= expand("<cword>")
9683 else
9684 let fname= ""
9685 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009686" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9687" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009688
9689 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009690" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009691 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009692" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009693
9694 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9695 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009696" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009697 1d
9698 endwhile
9699
Bram Moolenaar13600302014-05-22 18:26:40 +02009700 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009702" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009703 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704 endif
9705endfun
9706
9707" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009708" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009709" Normally, treetop is w:netrw_treetop, but a
9710" user of the function ( netrw#SetTreetop() )
9711" wipes that out prior to calling this function
9712fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009713" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9714 if line(".") < w:netrw_bannercnt + 2
9715 let treedir= a:treetop
9716 if treedir !~ '/$'
9717 let treedir= treedir.'/'
9718 endif
9719" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9720 return treedir
9721 endif
9722
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009723 let svpos = winsaveview()
9724" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009725 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009726" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009727 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9729 let curline= getline('.')
9730" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9731 if curline =~ '/$'
9732" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9733 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9734" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9735 elseif curline =~ '@\s\+-->'
9736" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9737 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9738 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9739" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009740 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009742 let treedir= ""
9743 endif
9744 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009745" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9746" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009747 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9748 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9749 let treedir= dirname.treedir
9750 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009751" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009752 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009753" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009754 if a:treetop =~ '/$'
9755 let treedir= a:treetop.treedir
9756 else
9757 let treedir= a:treetop.'/'.treedir
9758 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009759" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009761" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009762" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9763 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009764" call Dret("s:NetrwTreePath <".treedir.">")
9765 return treedir
9766endfun
9767
9768" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009769" s:NetrwWideListing: {{{2
9770fun! s:NetrwWideListing()
9771
9772 if w:netrw_liststyle == s:WIDELIST
9773" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9774 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009775 " cpf: characters per filename
9776 " fpl: filenames per line
9777 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009778 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009779 let dict={}
9780 " save the unnamed register and register 0-9 and a
9781 let dict.a=[getreg('a'), getregtype('a')]
9782 for i in range(0, 9)
9783 let dict[i] = [getreg(i), getregtype(i)]
9784 endfor
9785 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009786" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009787 let b:netrw_cpf= 0
9788 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009789 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009790 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9791 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009792 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009793 " restore stored registers
9794 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795" call Dret("NetrwWideListing")
9796 return
9797 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009798 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009799 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801
9802 " determine qty files per line (fpl)
9803 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9804 if w:netrw_fpl <= 0
9805 let w:netrw_fpl= 1
9806 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009807" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808
9809 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009810 " fpc: files per column of wide listing
9811 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009812 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9814 let newcolstart = w:netrw_bannercnt + fpc
9815 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009816" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009817 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009818" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009819 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009820 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009821 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 while line("$") >= newcolstart
9823 if newcolend > line("$") | let newcolend= line("$") | endif
9824 let newcolqty= newcolend - newcolstart
9825 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009826 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009828 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009829 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009830 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009831 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009832 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009833 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009835 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009836" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009837 if @* != keepregstar | sil! let @* = keepregstar | endif
9838 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009839 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009840 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9841 NetrwKeepj call histdel("/",-1)
9842 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9843 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009844" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009845 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009846 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009847" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009849 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009850 else
9851 if hasmapto("w","n")
9852 sil! nunmap <buffer> w
9853 endif
9854 if hasmapto("b","n")
9855 sil! nunmap <buffer> b
9856 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009857 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009858endfun
9859
9860" ---------------------------------------------------------------------
9861" s:PerformListing: {{{2
9862fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009863" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9864" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009865" call Decho("settings: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (enter)"." ei<".&ei.">",'~'.expand("<slnum>"))
9866 sil! NetrwKeepj %d _
9867" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868
Bram Moolenaar15146672011-10-20 22:22:38 +02009869 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009871 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009872
Bram Moolenaar85850f32019-07-19 22:05:51 +02009873 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009874 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009875" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876
9877" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009878" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879" endif " Decho
9880
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9883 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9885 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886 endif
9887
9888 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009890
9891 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009892 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895 if exists("g:netrw_pchk")
9896 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9897 " failure detections.
9898 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009899 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9901 endif
9902 if exists("g:netrw_pchk")
9903 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9904 else
9905 let curdir= b:netrw_curdir
9906 endif
9907 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9908 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9909 else
9910 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009911 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009912 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009913 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009914 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009916 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009917 let w:netrw_bannercnt= 1
9918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009919" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9920" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009921
Bram Moolenaar85850f32019-07-19 22:05:51 +02009922 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009923 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009924 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925 let sortby= sortby." reversed"
9926 endif
9927
9928 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009929 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009931 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009932" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009933 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009934 NetrwKeepj put ='\" Sorted by '.sortby
9935 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009936 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9937 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009939 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9942 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009944" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947
Bram Moolenaar85850f32019-07-19 22:05:51 +02009948 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009949 if g:netrw_banner
9950 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009951" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009952 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009953 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009955 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009956 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009957 endif
9958 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009959 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009960" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009963 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964
9965 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009966 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009967" call Decho("--handle hiding/showing in banner (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009968 if g:netrw_list_hide != "" && g:netrw_hide
9969 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009972 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009973 endif
9974 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009976 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009977
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009979 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009981 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009982" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009983 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009984 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009985" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009986" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009988
9989 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009990 if g:netrw_banner
9991 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" call Decho("--w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009994" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009995" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997
Bram Moolenaar446cb832008-06-24 21:56:24 +00009998 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009999" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010003 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010004 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010005" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010006" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10007 return
10008 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010
10011 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010012 if !exists("w:netrw_bannercnt")
10013 let w:netrw_bannercnt= 0
10014 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010015" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10016" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10017" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010018
Bram Moolenaar5c736222010-01-06 20:54:52 +010010019 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010020" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010022 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010023 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010025 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010028 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010030" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032
Bram Moolenaar5c736222010-01-06 20:54:52 +010010033 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010035 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010036 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010037 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 else
10039 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 endif
10042 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010043
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010046 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10047 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010048
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010049 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010050 " exten: sort by extension
10051 " The histdel(...,-1) calls remove the last search from the search history
10052" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010053 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10054 NetrwKeepj call histdel("/",-1)
10055 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10056 NetrwKeepj call histdel("/",-1)
10057 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10058 NetrwKeepj call histdel("/",-1)
10059 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10060" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010061 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062 " normal direction sorting
10063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10064 else
10065 " reverse direction sorting
10066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10067 endif
10068 endif
10069 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10070 NetrwKeepj call histdel("/",-1)
10071
Bram Moolenaar446cb832008-06-24 21:56:24 +000010072 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010073 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010074" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010075 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010076" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010077 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010078 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010080 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010081 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010082" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10084 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010085 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010086 endif
10087
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010088 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010089" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010090 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010091 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010092 call histdel("/",-1)
10093 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010094 endif
10095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010097
10098 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10100" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010101 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010103 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010105
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010106 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010107 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010109 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010110 endif
10111
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010113 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10115 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010116 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10118 else
10119" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10120" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10121" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10122" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010123 endif
10124
10125 " record previous current directory
10126 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010128
10129 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10131" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#4)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010132 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010134 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010136
10137 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010139 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010140" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010141 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010143 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10144 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010145" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010146" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010147
Bram Moolenaar8d043172014-01-23 14:24:41 +010010148 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10150" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#8)",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010151" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10152 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010153 unlet s:treecurpos
10154 endif
10155
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (return)",'~'.expand("<slnum>"))
10157" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010158" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10159endfun
10160
10161" ---------------------------------------------------------------------
10162" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010163fun! s:SetupNetrwStatusLine(statline)
10164" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10165
10166 if !exists("s:netrw_setup_statline")
10167 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010169
10170 if !exists("s:netrw_users_stl")
10171 let s:netrw_users_stl= &stl
10172 endif
10173 if !exists("s:netrw_users_ls")
10174 let s:netrw_users_ls= &laststatus
10175 endif
10176
10177 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010178 let dict={}
10179 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010180 redir @a
10181 try
10182 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010183 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010184 if &bg == "dark"
10185 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10186 else
10187 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10188 endif
10189 endtry
10190 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010191 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010192 endif
10193
10194 " set up status line (may use User9 highlighting)
10195 " insure that windows have a statusline
10196 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010197 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010198 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010199" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010200 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010201
10202" call Dret("SetupNetrwStatusLine : stl=".&stl)
10203endfun
10204
Bram Moolenaar85850f32019-07-19 22:05:51 +020010205" =========================================
10206" Remote Directory Browsing Support: {{{1
10207" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010208
10209" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010210" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10211" This function assumes that a long listing will be received. Size, time,
10212" and reverse sorts will be requested of the server but not otherwise
10213" enforced here.
10214fun! s:NetrwRemoteFtpCmd(path,listcmd)
10215" call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) w:netrw_method=".(exists("w:netrw_method")? w:netrw_method : (exists("b:netrw_method")? b:netrw_method : "???")))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010216" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010217 " sanity check: {{{3
10218 if !exists("w:netrw_method")
10219 if exists("b:netrw_method")
10220 let w:netrw_method= b:netrw_method
10221 else
10222 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10223" call Dret("NetrwRemoteFtpCmd")
10224 return
10225 endif
10226 endif
10227
10228 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10229 let ffkeep= &ff
10230 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010231" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010232
10233 " clear off any older non-banner lines " {{{3
10234 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010235" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10236 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010237
10238 ".........................................
10239 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10240 " ftp + <.netrc>: Method #2
10241 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010242 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 endif
10244 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010245 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010247 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010248 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010249" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010250 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010251" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
10252 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010253 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10255 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010256 endif
10257
10258 ".........................................
10259 elseif w:netrw_method == 3 " {{{3
10260 " ftp + machine,id,passwd,filename: Method #3
10261 setl ff=unix
10262 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010263 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010265 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 endif
10267
10268 " handle userid and password
10269 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010270" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010271 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10272 call NetUserPass("ftp:".host)
10273 endif
10274 if exists("g:netrw_uid") && g:netrw_uid != ""
10275 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010277 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010278 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010279 endif
10280 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 endif
10283 endif
10284
10285 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010286 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 endif
10288 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010290" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010291 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010293
10294 " perform ftp:
10295 " -i : turns off interactive prompting from ftp
10296 " -n unix : DON'T use <.netrc>, even though it exists
10297 " -n win32: quit being obnoxious about password
10298 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010299" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010300 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010301" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010302" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10303" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 endif
10305
10306 ".........................................
10307 elseif w:netrw_method == 9 " {{{3
10308 " sftp username@machine: Method #9
10309 " s:netrw_sftp_cmd
10310 setl ff=unix
10311
10312 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010313 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010314" call Dret("NetrwRemoteFtpCmd")
10315 return
10316
10317 ".........................................
10318 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010319 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 endif
10321
10322 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010323 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010324 sil! NetrwKeepj %s/\r$//e
10325 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010326 endif
10327 if a:listcmd == "dir"
10328 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010329 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10330 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10331 NetrwKeepj call histdel("/",-1)
10332 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010333 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010334 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10335 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010336 endif
10337 endif
10338
10339 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10340 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010341 exe 'NetrwKeepj '.w:netrw_bannercnt
10342 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 endif
10344 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010345 exe 'NetrwKeepj '.w:netrw_bannercnt
10346 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010347 endif
10348
10349 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010350 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010351" call Dret("NetrwRemoteFtpCmd")
10352endfun
10353
10354" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010355" s:NetrwRemoteListing: {{{2
10356fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010357" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010358
Bram Moolenaara6878372014-03-22 21:02:50 +010010359 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10360 let w:netrw_bannercnt= s:bannercnt
10361 endif
10362 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010363 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010364 endif
10365
Bram Moolenaar446cb832008-06-24 21:56:24 +000010366 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010367
Bram Moolenaar446cb832008-06-24 21:56:24 +000010368 " sanity check:
10369 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010370" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010372" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010373 if !exists("g:netrw_quiet")
10374 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10375 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010376 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010377" call Dret("s:NetrwRemoteListing -1")
10378 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010379 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010380
Bram Moolenaar8d043172014-01-23 14:24:41 +010010381 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010384 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010385 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your g:netrw_list_cmd is empty; perhaps ".g:netrw_ssh_cmd." is not executable on your system",47)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010387 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010389 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010390
Bram Moolenaar85850f32019-07-19 22:05:51 +020010391 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010392" call Dret("s:NetrwRemoteListing -1")
10393 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010395" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010396
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399 let w:netrw_method= b:netrw_method
10400 endif
10401
Bram Moolenaar13600302014-05-22 18:26:40 +020010402 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010403 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010404" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010405 let s:method = "ftp"
10406 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010407 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010409 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 let listcmd= g:netrw_ftp_sizelist_cmd
10411 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415
Bram Moolenaara6878372014-03-22 21:02:50 +010010416 " report on missing file or directory messages
10417 if search('[Nn]o such file or directory\|Failed to change directory')
10418 let mesg= getline(".")
10419 if exists("w:netrw_bannercnt")
10420 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010421 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010422 setl noma
10423 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010424 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 call netrw#ErrorMsg(s:WARNING,mesg,96)
10426" call Dret("s:NetrwRemoteListing : -1")
10427 return -1
10428 endif
10429
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010430 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010431 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010432" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010433 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434
10435 " cleanup
10436 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010437 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10438 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010440 sil! NetrwKeepj %s/\r$//e
10441 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010443 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010445 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010446 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010447" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010449" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010450 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010452 exe "sil! NetrwKeepj ".line1
10453 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010455" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10459 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010461" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10463 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10464 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10465 NetrwKeepj call histdel("/",-1)
10466 NetrwKeepj call histdel("/",-1)
10467 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 endif
10469 endif
10470
Bram Moolenaar13600302014-05-22 18:26:40 +020010471 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010473" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010474 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010477" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10478 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010480 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10481 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10482 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10483 NetrwKeepj call histdel("/",-1)
10484 NetrwKeepj call histdel("/",-1)
10485 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010487 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10488 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 endif
10490 else
10491 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010492" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010493 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010495" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10496 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10497" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010498 endif
10499 endif
10500
10501 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010502 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010503" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010504 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10505 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506 endif
10507 endif
10508
10509 if w:netrw_liststyle == s:LONGLIST
10510 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010511" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512
10513 if s:method == "ftp"
10514 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010515 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010516 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010517 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010519 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010521 sil! NetrwKeepj 1
10522 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 let line2= line(".")
10524 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010525 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010526 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 endif
10528 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe "sil! NetrwKeepj ".line1
10530 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 endif
10532
10533 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010534" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010535 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010537" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010539 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010540 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10541 NetrwKeepj call histdel("/",-1)
10542 NetrwKeepj call histdel("/",-1)
10543 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 endif
10545 endif
10546
10547" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010548" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010550
10551" call Dret("s:NetrwRemoteListing 0")
10552 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010553endfun
10554
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555" ---------------------------------------------------------------------
10556" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10557fun! s:NetrwRemoteRm(usrhost,path) range
10558" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010560 let svpos= winsaveview()
10561" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562
10563 let all= 0
10564 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10565 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 for fname in s:netrwmarkfilelist_{bufnr("%")}
10568 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010569 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010571 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572 let all= 1
10573 endif
10574 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010575 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576
10577 else
10578 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010579" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580
10581 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582 let keepsol = &l:sol
10583 setl nosol
10584 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585
10586 " remove multiple files and directories
10587 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010588 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010590 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010592 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593 let all= 1
10594 endif
10595 let ctr= ctr + 1
10596 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010597 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 endif
10599
10600 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010601" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010602 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605
10606" call Dret("s:NetrwRemoteRm")
10607endfun
10608
10609" ---------------------------------------------------------------------
10610" s:NetrwRemoteRmFile: {{{2
10611fun! s:NetrwRemoteRmFile(path,rmfile,all)
10612" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10613
10614 let all= a:all
10615 let ok = ""
10616
10617 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10618 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010619" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010620 if !all
10621 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 call inputsave()
10624 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10625 call inputrestore()
10626 echohl NONE
10627 if ok == ""
10628 let ok="no"
10629 endif
10630 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010631 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 let all= 1
10633 endif
10634 endif
10635
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010636 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010637" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010640 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010641 if path =~ '^\a\{3,}://'
10642 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010644 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10646 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010647" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010649" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010650 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010651 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652 let ok="q"
10653 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010654 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10656" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10657" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010661 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665 if v:shell_error != 0
10666 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010667 call netrw#ErrorMsg(s:ERROR,"remove failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",102)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 else
10669 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10670 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010671 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 endif
10676 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010677 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 endif
10680
10681 else
10682 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 if !all
10685 call inputsave()
10686 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10687 call inputrestore()
10688 if ok == ""
10689 let ok="no"
10690 endif
10691 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010692 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 let all= 1
10694 endif
10695 endif
10696
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010697 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010699 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700 else
10701 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010702 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10703" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010704 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010706
10707 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10709 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10710" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010711 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713
10714 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010715 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716 endif
10717 endif
10718 endif
10719
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010720 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010721" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010722 endif
10723 endif
10724
10725" call Dret("s:NetrwRemoteRmFile ".ok)
10726 return ok
10727endfun
10728
10729" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730" s:NetrwRemoteRename: rename a remote file or directory {{{2
10731fun! s:NetrwRemoteRename(usrhost,path) range
10732" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10733
10734 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010735 let svpos = winsaveview()
10736" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010737 let ctr = a:firstline
10738 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10739
10740 " rename files given by the markfilelist
10741 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10742 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010743" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010744 if exists("subfrom")
10745 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 else
10748 call inputsave()
10749 let newname= input("Moving ".oldname." to : ",oldname)
10750 call inputrestore()
10751 if newname =~ '^s/'
10752 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10753 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10754 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010755" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010756 endif
10757 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758
Bram Moolenaar446cb832008-06-24 21:56:24 +000010759 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010760 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010762 let oldname= s:ShellEscape(a:path.oldname)
10763 let newname= s:ShellEscape(a:path.newname)
10764" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010765 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766 endif
10767
10768 endfor
10769 call s:NetrwUnMarkFile(1)
10770
10771 else
10772
10773 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010774 let keepsol= &l:sol
10775 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010777 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010778
10779 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010780" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010781
10782 call inputsave()
10783 let newname= input("Moving ".oldname." to : ",oldname)
10784 call inputrestore()
10785
10786 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10787 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10788 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010789 let oldname= s:ShellEscape(a:path.oldname)
10790 let newname= s:ShellEscape(a:path.newname)
10791" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010792 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010793 endif
10794
10795 let ctr= ctr + 1
10796 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010797 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010798 endif
10799
10800 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010801 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010802" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10803 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010804
10805" call Dret("NetrwRemoteRename")
10806endfun
10807
Bram Moolenaar85850f32019-07-19 22:05:51 +020010808" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010809" Local Directory Browsing Support: {{{1
10810" ==========================================
10811
10812" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010813" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010814" Should accept: file://localhost/etc/fstab
10815" file:///etc/fstab
10816" file:///c:/WINDOWS/clock.avi
10817" file:///c|/WINDOWS/clock.avi
10818" file://localhost/c:/WINDOWS/clock.avi
10819" file://localhost/c|/WINDOWS/clock.avi
10820" file://c:/foo.txt
10821" file:///c:/foo.txt
10822" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
Bram Moolenaar85850f32019-07-19 22:05:51 +020010823fun! netrw#FileUrlEdit(fname)
10824" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010825 let fname = a:fname
10826 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010827" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010831 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010832 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010833" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010834 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010835" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836 endif
10837 endif
10838 let fname2396 = netrw#RFC2396(fname)
10839 let fname2396e= fnameescape(fname2396)
10840 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010841 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010844" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010845 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10846 endif
10847 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010848
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010849" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10850" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010851 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010852 exe 'NetrwKeepj keepalt edit '.plainfname
10853 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10854
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010856" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010857 exe "sil doau BufReadPost ".fname2396e
10858endfun
10859
10860" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010861" netrw#LocalBrowseCheck: {{{2
10862fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010863 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010864 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10865 "
10866 " unfortunate interaction -- split window debugging can't be used here, must use
10867 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10868 " another call to LocalBrowseCheck() when attempts to write
10869 " to the DBG buffer are made.
10870 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010871 " The &ft == "netrw" test was installed because the BufEnter event
10872 " would hit when re-entering netrw windows, creating unexpected
10873 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010874" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010875" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010876" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010877 " getting E930: Cannot use :redir inside execute
10878"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10880" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010881
Bram Moolenaar97d62492012-11-15 21:28:22 +010010882 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883 if isdirectory(s:NetrwFile(a:dirname))
10884" call Decho("is-directory ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$")." ft<".&ft."> g:netrw_fastbrowse=".g:netrw_fastbrowse,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010885
Bram Moolenaar97d62492012-11-15 21:28:22 +010010886 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10888" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010889 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010890
Bram Moolenaar446cb832008-06-24 21:56:24 +000010891 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010893 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010894
Bram Moolenaar5c736222010-01-06 20:54:52 +010010895 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010897 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010898 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010899 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010901" call Dret("netrw#LocalBrowseCheck")
10902 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010903 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010904
Bram Moolenaar85850f32019-07-19 22:05:51 +020010905 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010906 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10907 " AND IF the listing style is not a tree listing
10908 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010910 let ibuf = 1
10911 let buflast = bufnr("$")
10912 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10914 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010915 endif
10916 let ibuf= ibuf + 1
10917 endwhile
10918 endif
10919 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
10921" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010922 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010923" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924endfun
10925
10926" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010927" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010928" performed any shell command. The idea is to cause all local-browsing
10929" buffers to be refreshed after a user has executed some shell command,
10930" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010931fun! s:LocalBrowseRefresh()
10932" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010933" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10934" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010935
Bram Moolenaar446cb832008-06-24 21:56:24 +000010936 " determine which buffers currently reside in a tab
10937 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010938" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 return
10940 endif
10941 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010942" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943 return
10944 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010945 if !empty(getcmdwintype())
10946 " cannot move away from cmdline window, see :h E11
10947 return
10948 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010949 if exists("s:netrw_events") && s:netrw_events == 1
10950 " s:LocalFastBrowser gets called (indirectly) from a
10951 let s:netrw_events= 2
10952" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10953 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010954 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010955 let itab = 1
10956 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010957 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 while itab <= tabpagenr("$")
10959 let buftablist = buftablist + tabpagebuflist()
10960 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010961 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10964" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10966 " | refresh any netrw window
10967 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010968 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 let ibl = 0
10970 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010971" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10973 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010974 " (ibuf not shown in a current window AND
10975 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10977 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 continue
10981 elseif index(tabpagebuflist(),ibuf) != -1
10982 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010983" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010985 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010986 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10987 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10988 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10989 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010991 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10992 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10993 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010994 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010995 endif
10996 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010999" call Decho("restore window: win_gotoid(".curwinid.")")
11000 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011001 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011002
Bram Moolenaara6878372014-03-22 21:02:50 +010011003" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011004endfun
11005
11006" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011007" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11008"
11009" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011010" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011011" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11012" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014"
11015" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11016" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011017" (re-using a buffer may not be as accurate)
11018"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011019" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011020" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11021" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11022" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11023" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011025" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11026" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11027" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11028" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011029
11030 " initialize browselist, a list of buffer numbers that the local browser has used
11031 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011032" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011033 let s:netrw_browselist= []
11034 endif
11035
11036 " append current buffer to fastbrowse list
11037 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011039 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011040" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011041 endif
11042
11043 " enable autocmd events to handle refreshing/removing local browser buffers
11044 " If local browse buffer is currently showing: refresh it
11045 " If local browse buffer is currently hidden : wipe it
11046 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11047 " =1 : medium speed, re-use directory listing for remote only
11048 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011049 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11050 let s:netrw_events= 1
11051 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011053 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011054" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011055 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011056 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011058 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 endif
11060 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011061
11062 " user must have changed fastbrowse to its fast setting, so remove
11063 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011064 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011066 unlet s:netrw_events
11067 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011068 au!
11069 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011070 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071 endif
11072
Bram Moolenaar85850f32019-07-19 22:05:51 +020011073" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074endfun
11075
11076" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011077" s:LocalListing: does the job of "ls" for local directories {{{2
11078fun! s:LocalListing()
11079" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11081" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11082" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011083
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011084" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist",'~'.expand("<slnum>")) |endif
11085" if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist",'~'.expand("<slnum>"))|endif
11086" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011087
11088 " get the list of files contained in the current directory
11089 let dirname = b:netrw_curdir
11090 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011091 let filelist = s:NetrwGlob(dirname,"*",0)
11092 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011093" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011094
Nir Lichtman1e34b952024-05-08 19:19:34 +020011095 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011097 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11098 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011099" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011100 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011102 endif
11103
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011104" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011106" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107
11108 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11109 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11110 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11112" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115
11116 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" call Decho(" ",'~'.expand("<slnum>"))
11118" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011119
11120 if getftype(filename) == "link"
11121 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 let pfile= filename."@"
11124
11125 elseif getftype(filename) == "socket"
11126 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011128 let pfile= filename."="
11129
11130 elseif getftype(filename) == "fifo"
11131 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011132" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011133 let pfile= filename."|"
11134
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 let pfile= filename."/"
11139
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011141 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011142 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11143 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 let pfile= filename."*"
11146 else
11147 " normal file
11148 let pfile= filename
11149 endif
11150 elseif executable(filename)
11151 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 let pfile= filename."*"
11154 else
11155 " normal file
11156 let pfile= filename
11157 endif
11158
11159 else
11160 " normal file
11161 let pfile= filename
11162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011163" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011164
11165 if pfile =~ '//$'
11166 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011167" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011168 endif
11169 let pfile= strpart(pfile,dirnamelen)
11170 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011171" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11172" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011173
11174 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011175 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11176 let sz = getfsize(filename)
11177 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11178 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011179
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011180 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011181 let sz= s:NetrwHumanReadable(sz)
11182 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011183 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011184 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011185" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011186 endif
11187
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011188 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011189 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011190 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011191" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011192" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011193 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011194 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011195" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011197 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011198
11199 elseif g:netrw_sort_by =~ "^s"
11200 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011201" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011202" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011204 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011207 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011208
11209 else
11210 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011211" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011212" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011213 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011214 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011215" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011216 endfor
11217
11218 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011219 sil! NetrwKeepj g/^$/d
11220 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011221 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011222" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011223 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11224
11225" call Dret("s:LocalListing")
11226endfun
11227
11228" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011229" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11230fun! s:NetrwLocalExecute(cmd)
11231" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11232 let ykeep= @@
11233 " sanity check
11234 if !executable(a:cmd)
11235 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11236 let @@= ykeep
11237" call Dret("s:NetrwLocalExecute")
11238 return
11239 endif
11240
11241 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011242" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011243 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011244" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245
11246 " strip any ansi escape sequences off
11247 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11248
11249 " show user the result(s)
11250 echomsg result
11251 let @@= ykeep
11252
11253" call Dret("s:NetrwLocalExecute")
11254endfun
11255
11256" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011257" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011258fun! s:NetrwLocalRename(path) range
11259" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11260
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011261 if !exists("w:netrw_bannercnt")
11262 let w:netrw_bannercnt= b:netrw_bannercnt
11263 endif
11264
Bram Moolenaar97d62492012-11-15 21:28:22 +010011265 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011266 let ykeep = @@
11267 let ctr = a:firstline
11268 let svpos = winsaveview()
11269 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011270" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011271
11272 " rename files given by the markfilelist
11273 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11274 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011275" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011276 if exists("subfrom")
11277 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011278" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 else
11280 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011281 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011283 if newname =~ ''
11284 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11285 let newname = substitute(newname,'^.*','','')
11286 elseif newname =~ ''
11287 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11288 let newname = substitute(newname,'[^/]*','','')
11289 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011290 if newname =~ '^s/'
11291 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11292 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011293" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011294 let newname = substitute(oldname,subfrom,subto,'')
11295 endif
11296 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011297 if !all && filereadable(newname)
11298 call inputsave()
11299 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11300 call inputrestore()
11301 if response == "all"
11302 let all= 1
11303 elseif response != "y" && response != "yes"
11304 " refresh the directory
11305" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11306 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11307" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11308 NetrwKeepj call winrestview(svpos)
11309 let @@= ykeep
11310" call Dret("NetrwLocalRename")
11311 return
11312 endif
11313 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011314 call rename(oldname,newname)
11315 endfor
11316 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011317
Bram Moolenaar97d62492012-11-15 21:28:22 +010011318 else
11319
11320 " attempt to rename files/directories
11321 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011322 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011323
11324 " sanity checks
11325 if line(".") < w:netrw_bannercnt
11326 let ctr= ctr + 1
11327 continue
11328 endif
11329 let curword= s:NetrwGetWord()
11330 if curword == "./" || curword == "../"
11331 let ctr= ctr + 1
11332 continue
11333 endif
11334
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011335 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011336 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011337" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011338
11339 call inputsave()
11340 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11341 call inputrestore()
11342
11343 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011344" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011345
11346 let ctr= ctr + 1
11347 endwhile
11348 endif
11349
11350 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011351" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011352 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011353" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11354 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011355 let @@= ykeep
11356
11357" call Dret("NetrwLocalRename")
11358endfun
11359
11360" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361" s:NetrwLocalRm: {{{2
11362fun! s:NetrwLocalRm(path) range
11363" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011364" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011365
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011366 if !exists("w:netrw_bannercnt")
11367 let w:netrw_bannercnt= b:netrw_bannercnt
11368 endif
11369
Bram Moolenaar446cb832008-06-24 21:56:24 +000011370 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011371 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011372 let ret = 0
11373 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011374 let svpos = winsaveview()
11375" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011376
11377 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11378 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011379" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380 for fname in s:netrwmarkfilelist_{bufnr("%")}
11381 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011382 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011384 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385 let all= 1
11386 endif
11387 endfor
11388 call s:NetrwUnMarkFile(1)
11389
11390 else
11391 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011392" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011394 let keepsol= &l:sol
11395 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396 let ctr = a:firstline
11397 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011398 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399
11400 " sanity checks
11401 if line(".") < w:netrw_bannercnt
11402 let ctr= ctr + 1
11403 continue
11404 endif
11405 let curword= s:NetrwGetWord()
11406 if curword == "./" || curword == "../"
11407 let ctr= ctr + 1
11408 continue
11409 endif
11410 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011411 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011413 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 let all= 1
11415 endif
11416 let ctr= ctr + 1
11417 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011418 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011419 endif
11420
11421 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011422" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011423 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011424 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011425" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11426 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011427 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011428 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429
11430" call Dret("s:NetrwLocalRm")
11431endfun
11432
11433" ---------------------------------------------------------------------
11434" s:NetrwLocalRmFile: remove file fname given the path {{{2
11435" Give confirmation prompt unless all==1
11436fun! s:NetrwLocalRmFile(path,fname,all)
11437" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011438
Bram Moolenaar446cb832008-06-24 21:56:24 +000011439 let all= a:all
11440 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011441 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011442 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011443" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011444
11445 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11446 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011448 if !all
11449 echohl Statement
11450 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011451 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452 call inputrestore()
11453 echohl NONE
11454 if ok == ""
11455 let ok="no"
11456 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011457" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011458 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011460 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 let all= 1
11462 endif
11463 endif
11464
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011465 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011466 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011468 endif
11469
11470 else
11471 " attempt to remove directory
11472 if !all
11473 echohl Statement
11474 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011475 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011476 call inputrestore()
11477 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11478 if ok == ""
11479 let ok="no"
11480 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011481 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011482 let all= 1
11483 endif
11484 endif
11485 let rmfile= substitute(rmfile,'[\/]$','','e')
11486
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011487 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011488 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011489 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011490 endif
11491 endif
11492 endif
11493
11494" call Dret("s:NetrwLocalRmFile ".ok)
11495 return ok
11496endfun
11497
Bram Moolenaar85850f32019-07-19 22:05:51 +020011498" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011499" Support Functions: {{{1
11500
Bram Moolenaar488c6512005-08-11 20:09:58 +000011501" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011502" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11503" 0: marked file list of current buffer
11504" 1: marked file target
11505fun! netrw#Access(ilist)
11506 if a:ilist == 0
11507 if exists("s:netrwmarkfilelist_".bufnr('%'))
11508 return s:netrwmarkfilelist_{bufnr('%')}
11509 else
11510 return "no-list-buf#".bufnr('%')
11511 endif
11512 elseif a:ilist == 1
11513 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011514 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011515endfun
11516
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011517" ---------------------------------------------------------------------
11518" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11519fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011520 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011521endfun
11522
Bram Moolenaara6878372014-03-22 21:02:50 +010011523" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011524" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11525" I expect this function to be used in
11526" :PChkAssert netrw#Expose("netrwmarkfilelist")
11527" for example.
11528fun! netrw#Expose(varname)
11529" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011530 if exists("s:".a:varname)
11531 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011532" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011533 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011534" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011535 if type(retval) == 3
11536 let retval = copy(retval)
11537 let i = 0
11538 while i < len(retval)
11539 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11540 let i = i + 1
11541 endwhile
11542 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011543" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011544 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011545 else
11546" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011547 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011548 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011549" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011550 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011551 endif
11552
11553" call Dret("netrw#Expose ".string(retval))
11554 return retval
11555endfun
11556
11557" ---------------------------------------------------------------------
11558" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11559fun! netrw#Modify(varname,newvalue)
11560" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11561 exe "let s:".a:varname."= ".string(a:newvalue)
11562" call Dret("netrw#Modify")
11563endfun
11564
11565" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011566" netrw#RFC2396: converts %xx into characters {{{2
11567fun! netrw#RFC2396(fname)
11568" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011569 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011570" call Dret("netrw#RFC2396 ".fname)
11571 return fname
11572endfun
11573
11574" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011575" netrw#UserMaps: supports user-specified maps {{{2
11576" see :help function()
11577"
11578" g:Netrw_UserMaps is a List with members such as:
11579" [[keymap sequence, function reference],...]
11580"
11581" The referenced function may return a string,
11582" refresh : refresh the display
11583" -other- : this string will be executed
11584" or it may return a List of strings.
11585"
11586" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011587" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011588" Related functions:
11589" netrw#Expose(varname) -- see s:varname variables
11590" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11591" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11592fun! netrw#UserMaps(islocal)
11593" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11594" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11595
11596 " set up usermaplist
11597 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11598" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11599 for umap in g:Netrw_UserMaps
11600" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11601" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11602 " if umap[0] is a string and umap[1] is a string holding a function name
11603 if type(umap[0]) == 1 && type(umap[1]) == 1
11604" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11605 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11606 else
11607 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11608 endif
11609 endfor
11610 endif
11611" call Dret("netrw#UserMaps")
11612endfun
11613
11614" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011615" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11616fun! netrw#WinPath(path)
11617" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011618 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011619 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011620 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011621 " remove trailing slash (Win95)
11622 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11623 " remove escaped spaces
11624 let path = substitute(path, '\ ', ' ', 'g')
11625 " convert slashes to backslashes
11626 let path = substitute(path, '/', '\', 'g')
11627 else
11628 let path= a:path
11629 endif
11630" call Dret("netrw#WinPath <".path.">")
11631 return path
11632endfun
11633
11634" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011635" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11636fun! s:StripTrailingSlash(path)
11637 " remove trailing slash
11638 return substitute(a:path, '[/\\]$', '', 'g')
11639endfun
11640
Travis Sheltone34d0e32024-07-30 21:08:56 +020011641" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011642" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11643" cb : bl2mf=0 add marked files to buffer list
11644" cB : bl2mf=1 use bufferlist to mark files
11645" (mnemonic: cb = copy (marked files) to buffer list)
11646fun! s:NetrwBadd(islocal,bl2mf)
11647" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11648 if a:bl2mf
11649 " cB: add buffer list to marked files
11650 redir => bufl
11651 ls
11652 redir END
11653 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11654 for fname in bufl
11655 call s:NetrwMarkFile(a:islocal,fname)
11656 endfor
11657 else
11658 " cb: add marked files to buffer list
11659 for fname in s:netrwmarkfilelist_{bufnr("%")}
11660" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11661 exe "badd ".fnameescape(fname)
11662 endfor
11663 let curbufnr = bufnr("%")
11664 let curdir = s:NetrwGetCurdir(a:islocal)
11665 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11666 endif
11667" call Dret("s:NetrwBadd")
11668endfun
11669
11670" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011671" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11672fun! s:ComposePath(base,subdir)
11673" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11674
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011675 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011676" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011677 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011678 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011679 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011680 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011681 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011682 endif
11683
Bram Moolenaar85850f32019-07-19 22:05:51 +020011684 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011685 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011687 let ret= a:subdir
11688
Nir Lichtman1e34b952024-05-08 19:19:34 +020011689 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011690" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011691 if a:base =~ '[/\\]$'
11692 let ret= a:base.a:subdir
11693 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011694 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011695 endif
11696
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697 elseif a:base =~ '^\a\{3,}://'
11698" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011699 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11700 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11701 if a:subdir == '../'
11702 if curpath =~ '[^/]/[^/]\+/$'
11703 let curpath= substitute(curpath,'[^/]\+/$','','')
11704 else
11705 let curpath=""
11706 endif
11707 let ret= urlbase.curpath
11708 else
11709 let ret= urlbase.curpath.a:subdir
11710 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011711" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11712" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11713" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011714
11715 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011716" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011717 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11718 if a:base =~ '^//'
11719 " keeping initial '//' for the benefit of network share listing support
11720 let ret= '/'.ret
11721 endif
11722 let ret= simplify(ret)
11723 endif
11724
11725" call Dret("s:ComposePath ".ret)
11726 return ret
11727endfun
11728
11729" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011730" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11731" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11732fun! s:DeleteBookmark(fname)
11733" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11734 call s:MergeBookmarks()
11735
11736 if exists("g:netrw_bookmarklist")
11737 let indx= index(g:netrw_bookmarklist,a:fname)
11738 if indx == -1
11739 let indx= 0
11740 while indx < len(g:netrw_bookmarklist)
11741 if g:netrw_bookmarklist[indx] =~ a:fname
11742 call remove(g:netrw_bookmarklist,indx)
11743 let indx= indx - 1
11744 endif
11745 let indx= indx + 1
11746 endwhile
11747 else
11748 " remove exact match
11749 call remove(g:netrw_bookmarklist,indx)
11750 endif
11751 endif
11752
11753" call Dret("s:DeleteBookmark")
11754endfun
11755
11756" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011757" s:FileReadable: o/s independent filereadable {{{2
11758fun! s:FileReadable(fname)
11759" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11760
11761 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011762 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011763 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011764 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011765 endif
11766
11767" call Dret("s:FileReadable ".ret)
11768 return ret
11769endfun
11770
11771" ---------------------------------------------------------------------
11772" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11773" Places correct suffix on end of temporary filename,
11774" using the suffix provided with fname
11775fun! s:GetTempfile(fname)
11776" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11777
11778 if !exists("b:netrw_tmpfile")
11779 " get a brand new temporary filename
11780 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011781" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011782
Bram Moolenaarc236c162008-07-13 17:41:49 +000011783 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011784" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011785
Bram Moolenaar9964e462007-05-05 17:54:07 +000011786 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011787 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11788" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011789 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011790" call Dret("s:GetTempfile getcwd<".getcwd().">")
11791 return ""
11792 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011793
Bram Moolenaar9964e462007-05-05 17:54:07 +000011794 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011795 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011796" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011797
Bram Moolenaar9964e462007-05-05 17:54:07 +000011798 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011799 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011800 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011801 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802 if !exists("+shellslash") || !&ssl
11803 let tmpfile = substitute(tmpfile,'/','\','g')
11804 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011806 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011807 endif
11808 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011809" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 else
11811 " re-use temporary filename
11812 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011813" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 endif
11815
11816 " use fname's suffix for the temporary file
11817 if a:fname != ""
11818 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011819" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011820 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011821 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011822 elseif a:fname =~ '.txz$'
11823 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 else
11825 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11826 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011827" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011829" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011830 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011832 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11833 endif
11834 endif
11835
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011837" call Dret("s:GetTempfile <".tmpfile.">")
11838 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011839endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840
11841" ---------------------------------------------------------------------
11842" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011843" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011844fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011845" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011846 if s:user == ""
11847 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11848 else
11849 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11850 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011851 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011852 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011853 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011854 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011855 else
11856 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11857 endif
11858" call Dret("s:MakeSshCmd <".sshcmd.">")
11859 return sshcmd
11860endfun
11861
11862" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011863" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11864fun! s:MakeBookmark(fname)
11865" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11866
11867 if !exists("g:netrw_bookmarklist")
11868 let g:netrw_bookmarklist= []
11869 endif
11870
11871 if index(g:netrw_bookmarklist,a:fname) == -1
11872 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011873 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011874 call add(g:netrw_bookmarklist,a:fname.'/')
11875 elseif a:fname !~ '/'
11876 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11877 else
11878 call add(g:netrw_bookmarklist,a:fname)
11879 endif
11880 call sort(g:netrw_bookmarklist)
11881 endif
11882
11883" call Dret("s:MakeBookmark")
11884endfun
11885
11886" ---------------------------------------------------------------------
11887" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11888fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011889" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011890 " get bookmarks from .netrwbook file
11891 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892 if filereadable(s:NetrwFile(savefile))
11893" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011894 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011896 NetrwKeepj call delete(savefile)
11897 endif
11898" call Dret("s:MergeBookmarks")
11899endfun
11900
11901" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011902" s:NetrwBMShow: {{{2
11903fun! s:NetrwBMShow()
11904" call Dfunc("s:NetrwBMShow()")
11905 redir => bmshowraw
11906 menu
11907 redir END
11908 let bmshowlist = split(bmshowraw,'\n')
11909 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011910 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011911 if bmshowfuncs != []
11912 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011913 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011914 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011915 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011916 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011917 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11919endfun
11920
11921" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011922" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011923fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011924 if !exists("w:netrw_liststyle")
11925 let w:netrw_liststyle= g:netrw_liststyle
11926 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011927" call Dfunc("s:NetrwCursor() ft<".&ft."> liststyle=".w:netrw_liststyle." g:netrw_cursor=".g:netrw_cursor." s:netrw_usercuc=".s:netrw_usercuc." s:netrw_usercul=".s:netrw_usercul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011928
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011929" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11930
Bram Moolenaaradc21822011-04-01 18:03:16 +020011931 if &ft != "netrw"
11932 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11933 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011934" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011935
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011936 elseif g:netrw_cursor == 8
11937 if w:netrw_liststyle == s:WIDELIST
11938 setl cursorline
11939 setl cursorcolumn
11940 else
11941 setl cursorline
11942 endif
11943 elseif g:netrw_cursor == 7
11944 setl cursorline
11945 elseif g:netrw_cursor == 6
11946 if w:netrw_liststyle == s:WIDELIST
11947 setl cursorline
11948 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011949 elseif g:netrw_cursor == 4
11950 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011952 setl cursorline
11953 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011954
11955 elseif g:netrw_cursor == 3
11956 " thin-long-tree: cursorline, user's cursorcolumn
11957 " wide : cursorline, cursorcolumn
11958 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011959" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011960 setl cursorline
11961 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011962 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011963" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011964 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011965 endif
11966
11967 elseif g:netrw_cursor == 2
11968 " thin-long-tree: cursorline, user's cursorcolumn
11969 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011971 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972
11973 elseif g:netrw_cursor == 1
11974 " thin-long-tree: user's cursorline, user's cursorcolumn
11975 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011976 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011977" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011978 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011981 endif
11982
11983 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011984 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011985" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011986 let &l:cursorline = s:netrw_usercul
11987 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011988 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011990" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011991" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011992endfun
11993
11994" ---------------------------------------------------------------------
11995" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11996fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011997" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011998 if exists("s:netrw_usercul")
11999 let &l:cursorline = s:netrw_usercul
12000 endif
12001 if exists("s:netrw_usercuc")
12002 let &l:cursorcolumn = s:netrw_usercuc
12003 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012004" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012005" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12006endfun
12007
Christian Brabandt62f7b552024-06-23 20:23:40 +020012008" s:RestoreRegister: restores all registers given in the dict {{{2
12009fun! s:RestoreRegister(dict)
12010 for [key, val] in items(a:dict)
12011 if key == 'unnamed'
12012 let key = ''
12013 endif
12014 call setreg(key, val[0], val[1])
12015 endfor
12016endfun
12017
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012018" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012019" s:NetrwDelete: Deletes a file. {{{2
12020" Uses Steve Hall's idea to insure that Windows paths stay
12021" acceptable. No effect on Unix paths.
12022" Examples of use: let result= s:NetrwDelete(path)
12023fun! s:NetrwDelete(path)
12024" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12025
Bram Moolenaar5c736222010-01-06 20:54:52 +010012026 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012027 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012028 if exists("+shellslash")
12029 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012030 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012031 let result = delete(path)
12032 let &shellslash = sskeep
12033 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012034" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012035 let result= delete(path)
12036 endif
12037 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012038" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 let result= delete(path)
12040 endif
12041 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012042 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012043 endif
12044
12045" call Dret("s:NetrwDelete ".result)
12046 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012047endfun
12048
12049" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012050" s:NetrwBufRemover: removes a buffer that: {{{2s
12051" has buffer-id > 1
12052" is unlisted
12053" is unnamed
12054" does not appear in any window
12055fun! s:NetrwBufRemover(bufid)
12056" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12057" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12058" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12059" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12060" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12061
yasuda4dbb2662023-10-04 20:50:35 +020012062 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012063" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012064 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012065 endif
12066
12067" call Dret("s:NetrwBufRemover")
12068endfun
12069
12070" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012071" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012072fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012073" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012074" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012075
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012076 " Clean out the last buffer:
12077 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12078 " If so, delete it.
12079 call s:NetrwBufRemover(bufnr("$"))
12080
Bram Moolenaar446cb832008-06-24 21:56:24 +000012081 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012082" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012083 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12084 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12085 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12086 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12087 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12088 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12089 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12090 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12091 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12092 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12093 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12094 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12095 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12096 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12097 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12098 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12099
Bram Moolenaar85850f32019-07-19 22:05:51 +020012100 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012101" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012102 " when tree listing uses file TreeListing... a new buffer is made.
12103 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012104 " COMBAK: this causes a problem, see P43
12105" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012106 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012107 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012108 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012109" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012110 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012111
Bram Moolenaar446cb832008-06-24 21:56:24 +000012112 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012113" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012114 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12115 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12116 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12117 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12118 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12119 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12120 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12121 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12122 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12123 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12124 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12125 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12126 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12127 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12128 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12129 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12130
Bram Moolenaar5c736222010-01-06 20:54:52 +010012131 if a:0 > 0
12132 let b:netrw_curdir= a:1
12133 if b:netrw_curdir =~ '/$'
12134 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012135 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012136 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012137 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012138 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12139 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012140 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012141 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012142 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012143 endif
12144 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012145 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12146 let &l:bexpr = "netrw#BalloonHelp()"
12147 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012148
Bram Moolenaar8d043172014-01-23 14:24:41 +010012149" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012150endfun
12151
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012152" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012153" s:NetrwExe: executes a string using "!" {{{2
12154fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012155" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012156 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012157" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012158 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12159 set shell& shellcmdflag& shellxquote& shellxescape&
12160 set shellquote& shellpipe& shellredir& shellslash&
12161 exe a:cmd
12162 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12163 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012165 exe a:cmd
12166 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012167 if v:shell_error
12168 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12169 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012170" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012171endfun
12172
12173" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012174" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12175fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012176 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012177" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012178 let curbuf = bufnr("%")
12179 let curwin = winnr()
12180 let iwin = 1
12181 while iwin <= winnr("$")
12182 exe iwin."wincmd w"
12183 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12184 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12185 let winvars= w:
12186 break
12187 endif
12188 let iwin= iwin + 1
12189 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012190 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012191 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012192" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012193 for k in keys(winvars)
12194 let w:{k}= winvars[k]
12195 endfor
12196 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012197" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012198 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012199endfun
12200
Bram Moolenaara6878372014-03-22 21:02:50 +010012201" ---------------------------------------------------------------------
12202" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012203" Returns: 0=success
12204" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012205fun! s:NetrwLcd(newdir)
12206" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012207" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012208
Bram Moolenaar85850f32019-07-19 22:05:51 +020012209 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012210 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012211 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012212 catch /^Vim\%((\a\+)\)\=:E344/
12213 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12214 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012215 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012216 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12217 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012218 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12220 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012221 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 endif
12223 endif
12224 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012225 let err472= 1
12226 endtry
12227
12228 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12230 if exists("w:netrw_prvdir")
12231 let a:newdir= w:netrw_prvdir
12232 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012233 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012234" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012235 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012236" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012237 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012238 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012239" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12240 return -1
12241 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012242
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012243" call Decho("getcwd <".getcwd().">")
12244" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012245" call Dret("s:NetrwLcd 0")
12246 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012247endfun
12248
Bram Moolenaar9964e462007-05-05 17:54:07 +000012249" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012250" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12251" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12252fun! s:NetrwSaveWordPosn()
12253" call Dfunc("NetrwSaveWordPosn()")
12254 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12255" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12256endfun
12257
12258" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012259" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12260" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12261fun! s:NetrwHumanReadable(sz)
12262" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12263
12264 if g:netrw_sizestyle == 'h'
12265 if a:sz >= 1000000000
12266 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12267 elseif a:sz >= 10000000
12268 let sz = printf("%d",a:sz/1000000)."m"
12269 elseif a:sz >= 1000000
12270 let sz = printf("%.1f",a:sz/1000000.0)."m"
12271 elseif a:sz >= 10000
12272 let sz = printf("%d",a:sz/1000)."k"
12273 elseif a:sz >= 1000
12274 let sz = printf("%.1f",a:sz/1000.0)."k"
12275 else
12276 let sz= a:sz
12277 endif
12278
12279 elseif g:netrw_sizestyle == 'H'
12280 if a:sz >= 1073741824
12281 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12282 elseif a:sz >= 10485760
12283 let sz = printf("%d",a:sz/1048576)."M"
12284 elseif a:sz >= 1048576
12285 let sz = printf("%.1f",a:sz/1048576.0)."M"
12286 elseif a:sz >= 10240
12287 let sz = printf("%d",a:sz/1024)."K"
12288 elseif a:sz >= 1024
12289 let sz = printf("%.1f",a:sz/1024.0)."K"
12290 else
12291 let sz= a:sz
12292 endif
12293
12294 else
12295 let sz= a:sz
12296 endif
12297
12298" call Dret("s:NetrwHumanReadable ".sz)
12299 return sz
12300endfun
12301
12302" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012303" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12304" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12305fun! s:NetrwRestoreWordPosn()
12306" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012307 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012308" call Dret("NetrwRestoreWordPosn")
12309endfun
12310
12311" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012312" s:RestoreBufVars: {{{2
12313fun! s:RestoreBufVars()
12314" call Dfunc("s:RestoreBufVars()")
12315
12316 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12317 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12318 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12319 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12320 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12321 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12322
12323" call Dret("s:RestoreBufVars")
12324endfun
12325
12326" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012327" s:RemotePathAnalysis: {{{2
12328fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012329" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012330
Bram Moolenaara6878372014-03-22 21:02:50 +010012331 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012332 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012333 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012334 let s:user = substitute(a:dirname,dirpat,'\3','')
12335 let s:machine = substitute(a:dirname,dirpat,'\4','')
12336 let s:port = substitute(a:dirname,dirpat,'\5','')
12337 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012338 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012339 if s:machine =~ '@'
12340 let dirpat = '^\(.*\)@\(.\{-}\)$'
12341 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12342 let s:machine = substitute(s:machine,dirpat,'\2','')
12343 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012344
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012345" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12346" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12347" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12348" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12349" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12350" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012351
12352" call Dret("s:RemotePathAnalysis")
12353endfun
12354
12355" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012356" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12357" Returns status
12358" Runs system() on
12359" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012360" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012361fun! s:RemoteSystem(cmd)
12362" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12363 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012364 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012365 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012366 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012367 else
12368 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12369 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12370 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012371 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012372 else
12373 let cmd= cmd.' '
12374 endif
12375 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012376" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012377 let ret= system(cmd)
12378 endif
12379" call Dret("s:RemoteSystem ".ret)
12380 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012381endfun
12382
12383" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012384" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012385fun! s:RestoreWinVars()
12386" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012387 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012388 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12389 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12390 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12391 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12392 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12393 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12394 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12395 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12396 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12397 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12398 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12399 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012400 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12401 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012402 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12403 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12404 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12405" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012406endfun
12407
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012408" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012409" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12410"
12411" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12412" is true) and a command, :Rexplore, which call this function.
12413"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012414" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012415"
12416" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012417fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012418 if exists("s:netrwdrag")
12419 return
12420 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012421" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir."> win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012422" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12423" call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012424
12425 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012426 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012427" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012428 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012429 unlet w:netrw_rexfile
12430" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012431 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012432" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012433" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12434" call Decho("treating as not-netrw-buffer: w:netrw_rexfile<".((exists("w:netrw_rexfile"))? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020012435 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012436
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012437 " ---------------------------
12438 " :Rex issued while in a file
12439 " ---------------------------
12440
Bram Moolenaara6878372014-03-22 21:02:50 +010012441 " record current file so :Rex can return to it from netrw
12442 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012443" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012444
12445 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012446" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012447 return
12448 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012449" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012450 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012451 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012452 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012453 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012454 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012455 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012456 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012457 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012458 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12460 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012461" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12462 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012463 if exists("s:rexposn_".bufnr('%'))
12464 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012465 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012466 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012467" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012468 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012469
Bram Moolenaar85850f32019-07-19 22:05:51 +020012470 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12471 if exists("s:explore_match")
12472 exe "2match netrwMarkFile /".s:explore_match."/"
12473 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012474 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012475
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012476" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012477" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012478endfun
12479
12480" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012481" s:SaveBufVars: save selected b: variables to s: variables {{{2
12482" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012483fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012484" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012485
12486 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12487 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12488 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12489 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12490 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12491 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12492
12493" call Dret("s:SaveBufVars")
12494endfun
12495
12496" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012497" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12498fun! s:SavePosn(posndict)
12499" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12500
Bram Moolenaar85850f32019-07-19 22:05:51 +020012501 if !exists("a:posndict[bufnr('%')]")
12502 let a:posndict[bufnr("%")]= []
12503 endif
12504" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12505 call add(a:posndict[bufnr("%")],winsaveview())
12506" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012507
12508" call Dret("s:SavePosn posndict")
12509 return a:posndict
12510endfun
12511
12512" ---------------------------------------------------------------------
12513" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12514fun! s:RestorePosn(posndict)
12515" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012516 if exists("a:posndict")
12517 if has_key(a:posndict,bufnr("%"))
12518" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12519 let posnlen= len(a:posndict[bufnr("%")])
12520 if posnlen > 0
12521 let posnlen= posnlen - 1
12522" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12523 call winrestview(a:posndict[bufnr("%")][posnlen])
12524 call remove(a:posndict[bufnr("%")],posnlen)
12525" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12526 endif
12527 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012528 endif
12529" call Dret("s:RestorePosn")
12530endfun
12531
12532" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012533" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012534fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012535" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012536 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12537 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12538 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12539 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12540 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12541 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12542 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12543 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12544 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12545 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12546 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12547 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12548 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12549 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12550 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12551 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12552 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12553 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12554" call Dret("s:SaveWinVars")
12555endfun
12556
12557" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012558" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012559" To allow separate windows to have their own activities, such as
12560" Explore **/pattern, several variables have been made window-oriented.
12561" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012562" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012563" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012564fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012565" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012566 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12567 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12568 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12569 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12570 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12571 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12572 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12573 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12574 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12575 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12576" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012577endfun
12578
12579" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012580" s:SetRexDir: set directory for :Rexplore {{{2
12581fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012582" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012583 let w:netrw_rexdir = a:dirname
12584 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012585 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012586" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12587" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012588" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012589" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012590" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012591endfun
12592
12593" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012594" s:ShowLink: used to modify thin and tree listings to show links {{{2
12595fun! s:ShowLink()
12596" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012597" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12598" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012599 if exists("b:netrw_curdir")
12600 norm! $?\a
12601 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12602 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012603" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12604" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12605" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12606 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012607 let dirlen = strlen(b:netrw_curdir)
12608 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012609" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012610 endif
12611 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012612" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12613" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012614 setl noro ma
12615 call setline(".",modline)
12616 setl ro noma nomod
12617 endif
12618" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12619endfun
12620
12621" ---------------------------------------------------------------------
12622" s:ShowStyle: {{{2
12623fun! s:ShowStyle()
12624 if !exists("w:netrw_liststyle")
12625 let liststyle= g:netrw_liststyle
12626 else
12627 let liststyle= w:netrw_liststyle
12628 endif
12629 if liststyle == s:THINLIST
12630 return s:THINLIST.":thin"
12631 elseif liststyle == s:LONGLIST
12632 return s:LONGLIST.":long"
12633 elseif liststyle == s:WIDELIST
12634 return s:WIDELIST.":wide"
12635 elseif liststyle == s:TREELIST
12636 return s:TREELIST.":tree"
12637 else
12638 return 'n/a'
12639 endif
12640endfun
12641
12642" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012643" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12644" Solution from Nicolai Weibull, vim docs (:help strlen()),
12645" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012646fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012647" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12648
12649 if v:version >= 703 && exists("*strdisplaywidth")
12650 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012651
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 elseif type(g:Align_xstrlen) == 1
12653 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12654 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012655
Bram Moolenaar8d043172014-01-23 14:24:41 +010012656 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012657 " number of codepoints (Latin a + combining circumflex is two codepoints)
12658 " (comment from TM, solution from NW)
12659 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012660
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 elseif g:Align_xstrlen == 2
12662 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012663 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12664 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012665 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012666
Bram Moolenaar8d043172014-01-23 14:24:41 +010012667 elseif g:Align_xstrlen == 3
12668 " virtual length (counting, for instance, tabs as anything between 1 and
12669 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670 " preceded by lam, one otherwise, etc.)
12671 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012672 let modkeep= &l:mod
12673 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012674 call setline(line("."),a:x)
12675 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012676 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012677 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012678 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012679
Bram Moolenaar446cb832008-06-24 21:56:24 +000012680 else
12681 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012682 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012685 return ret
12686endfun
12687
12688" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012689" s:ShellEscape: shellescape(), or special windows handling {{{2
12690fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012691 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012692 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12693 endif
12694 let f = a:0 > 0 ? a:1 : 0
12695 return shellescape(a:s, f)
12696endfun
12697
12698" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012699" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012700fun! s:TreeListMove(dir)
12701" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012702 let curline = getline('.')
12703 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12704 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12705 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12706 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12707 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12708 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12709" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12710" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12711" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12712" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12713" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12714 " COMBAK : need to handle when on a directory
12715 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012716 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012717 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012718 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012719 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012720" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012721 elseif a:dir == '[]' && nxtline != ''
12722 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012723" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012724 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12725 if nl != 0
12726 NetrwKeepj norm! k
12727 else
12728 NetrwKeepj norm! G
12729 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012730" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012731 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012732 endif
12733
12734" call Dret("s:TreeListMove")
12735endfun
12736
12737" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012738" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12739" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12740" can't be called except via emenu. But due to locale, that menu line may not be called
12741" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12742fun! s:UpdateBuffersMenu()
12743" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012744 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012745 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012746 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012747 catch /^Vim\%((\a\+)\)\=:E/
12748 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012749 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012750 endtry
12751 endif
12752" call Dret("s:UpdateBuffersMenu")
12753endfun
12754
12755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012756" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012757" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012758fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012759" call Dfunc("s:UseBufWinVars()")
12760 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012761 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12762 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12763 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12764 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12765 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12766 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12767 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12768 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12769 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012770" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012771endfun
12772
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012773" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012774" s:UserMaps: supports user-defined UserMaps {{{2
12775" * calls a user-supplied funcref(islocal,curdir)
12776" * interprets result
12777" See netrw#UserMaps()
12778fun! s:UserMaps(islocal,funcname)
12779" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12780
12781 if !exists("b:netrw_curdir")
12782 let b:netrw_curdir= getcwd()
12783 endif
12784 let Funcref = function(a:funcname)
12785 let result = Funcref(a:islocal)
12786
12787 if type(result) == 1
12788 " if result from user's funcref is a string...
12789" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12790 if result == "refresh"
12791" call Decho("refreshing display",'~'.expand("<slnum>"))
12792 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12793 elseif result != ""
12794" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12795 exe result
12796 endif
12797
12798 elseif type(result) == 3
12799 " if result from user's funcref is a List...
12800" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12801 for action in result
12802 if action == "refresh"
12803" call Decho("refreshing display",'~'.expand("<slnum>"))
12804 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12805 elseif action != ""
12806" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12807 exe action
12808 endif
12809 endfor
12810 endif
12811
12812" call Dret("s:UserMaps")
12813endfun
12814
Bram Moolenaar85850f32019-07-19 22:05:51 +020012815" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012816" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012817" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012818let &cpo= s:keepcpo
12819unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012820
Bram Moolenaar85850f32019-07-19 22:05:51 +020012821" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012822" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012823" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012824" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012825" doing autoload/netrw.vim version v172g ~57
12826" varname<g:netrw_dirhistcnt> value=0 ~1
12827" varname<s:THINLIST> value=0 ~1
12828" varname<s:LONGLIST> value=1 ~1
12829" varname<s:WIDELIST> value=2 ~1
12830" varname<s:TREELIST> value=3 ~1
12831" varname<s:MAXLIST> value=4 ~1
12832" varname<g:netrw_use_errorwindow> value=2 ~1
12833" varname<g:netrw_http_xcmd> value=-q -O ~1
12834" varname<g:netrw_http_put_cmd> value=curl -T ~1
12835" varname<g:netrw_keepj> value=keepj ~1
12836" varname<g:netrw_rcp_cmd> value=rcp ~1
12837" varname<g:netrw_rsync_cmd> value=rsync ~1
12838" varname<g:netrw_rsync_sep> value=/ ~1
12839" varname<g:netrw_scp_cmd> value=scp -q ~1
12840" varname<g:netrw_sftp_cmd> value=sftp ~1
12841" varname<g:netrw_ssh_cmd> value=ssh ~1
12842" varname<g:netrw_alto> value=0 ~1
12843" varname<g:netrw_altv> value=1 ~1
12844" varname<g:netrw_banner> value=1 ~1
12845" varname<g:netrw_browse_split> value=0 ~1
12846" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12847" varname<g:netrw_chgwin> value=-1 ~1
12848" varname<g:netrw_clipboard> value=1 ~1
12849" varname<g:netrw_compress> value=gzip ~1
12850" varname<g:netrw_ctags> value=ctags ~1
12851" varname<g:netrw_cursor> value=2 ~1
12852" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12853" varname<g:netrw_cygdrive> value=/cygdrive ~1
12854" varname<s:didstarstar> value=0 ~1
12855" varname<g:netrw_dirhistcnt> value=0 ~1
12856" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12857" varname<g:netrw_dirhistmax> value=10 ~1
12858" varname<g:netrw_errorlvl> value=0 ~1
12859" varname<g:netrw_fastbrowse> value=1 ~1
12860" varname<g:netrw_ftp_browse_reject> value=^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$ ~1
12861" varname<g:netrw_ftpmode> value=binary ~1
12862" varname<g:netrw_hide> value=1 ~1
12863" varname<g:netrw_keepdir> value=1 ~1
12864" varname<g:netrw_list_hide> value= ~1
12865" varname<g:netrw_localmkdir> value=mkdir ~1
12866" varname<g:netrw_remote_mkdir> value=mkdir ~1
12867" varname<g:netrw_liststyle> value=0 ~1
12868" varname<g:netrw_markfileesc> value=*./[\~ ~1
12869" varname<g:netrw_maxfilenamelen> value=32 ~1
12870" varname<g:netrw_menu> value=1 ~1
12871" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12872" varname<g:netrw_mousemaps> value=1 ~1
12873" varname<g:netrw_retmap> value=0 ~1
12874" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12875" varname<g:netrw_preview> value=0 ~1