[PATCH] netrw: make gx work again

24 views
Skip to first unread message

Felipe Contreras

unread,
May 30, 2021, 4:11:59 PM5/30/21
to vim...@vim.org, Bram Moolenaar, Charles Campbell, Felipe Contreras, Charles E Campbell
vim v8.1.1714 introduced a huge regression that basically made gx
unusable (see issue #4738) thanks to 85850f3a5 (Update runtime files,
2019-07-19).

The gx mapping used to call CheckIfRemote() which always returned 0,
When vim was updated to version 165 it was changed to
CheckIfRemote(netrw#GX()), which for any links (e.g. http) returned 1.

This caused netrw to download the URL first, and then open the file,
which is clearly wrong and caused many issues.

In the most recent version (171g) Campbell introduced a new
configuration variable `netrw_browsex_support_remote` which can be set
to 0 to induce the new behavior, but otherwise the old behavior is kept.

This was backported from Charles Campbell's site (after the server
finally decided to serve me).

Fixes #4738.

[1] http://www.drchip.org/astronaut/vim/index.html#NETRW

Original-code-by: Charles E Campbell <no...@devnull.org>
Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
runtime/autoload/netrw.vim | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index d095f6dd8..8ec46eed5 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -5264,6 +5264,12 @@ fun! netrw#BrowseX(fname,remote)
endif
" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))

+ if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
+ let remote = a:remote
+ else
+ let remote = 0
+ endif
+
let ykeep = @@
let screenposn = winsaveview()
" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
@@ -5308,9 +5314,9 @@ fun! netrw#BrowseX(fname,remote)
endif
" call Decho("exten<".exten.">",'~'.expand("<slnum>"))

- if a:remote == 1
+ if remote == 1
" create a local copy
-" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
+" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
setl bh=delete
call netrw#NetRead(3,a:fname)
" attempt to rename tempfile
@@ -5332,7 +5338,7 @@ fun! netrw#BrowseX(fname,remote)
let fname= s:netrw_tmpfile
endif
else
-" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
+" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
let fname= a:fname
" special ~ handler for local
if fname =~ '^\~' && expand("$HOME") != ""
@@ -5475,12 +5481,12 @@ fun! netrw#BrowseX(fname,remote)
" return to prior buffer (directory listing)
" Feb 12, 2008: had to de-activiate removal of
" temporary file because it wasn't getting seen.
-" if a:remote == 1 && fname != a:fname
+" if remote == 1 && fname != a:fname
"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
" call s:NetrwDelete(fname)
" endif

- if a:remote == 1
+ if remote == 1
setl bh=delete bt=nofile
if g:netrw_use_noswf
setl noswf
--
2.32.0.rc0

Felipe Contreras

unread,
May 30, 2021, 4:14:34 PM5/30/21
to vim...@vim.org, Bram Moolenaar, Charles Campbell
On Sun, May 30, 2021 at 3:11 PM Felipe Contreras
<felipe.c...@gmail.com> wrote:
>
> vim v8.1.1714 introduced a huge regression that basically made gx
> unusable (see issue #4738) thanks to 85850f3a5 (Update runtime files,
> 2019-07-19).

Please don't reply to the original mail, reply to this one. I never
get right Campbell's email.

--
Felipe Contreras
Reply all
Reply to author
Forward
0 new messages