Sunday, December 22, 2013

Netrw issues with tempfiles under gVim + Cygwin

Hi,

I set out to investigate and solve some of the things that are supposed to work
out-of-the box in Vim but, for some reason, they don't. One of the issues is
that Netrw isn't able to download files through http. Before going into the
details, it is important to note that I'm using a rather non-standard
configuration of Windows native gVim with shell set to Cygwin's bash. This has
been working without issues for some years now.

Both gVim and Cygwin's console Vim have identical patch level:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep 13 2013 00:18:48)
Included patches: 1-1314
Compiled by <cygwin@cygwin.com>

MS-Windows 32-bit GUI version with OLE support
Included patches: 1-1314
Compiled by Yongwei@Shanghai

Under Cygwin, the .vim folder is symlinked to my gVim's 'vimfiles' folder.

The shell configuration part in vimfiles/gvimrc is as follows:

set shell = $HOME\cygwin\bin\bash
let &shellcmdflag = '-c'
set shellxquote = \"
set shellslash
let $BASH_ENV = '~/.bashrc'

It works just great. I can transparently use all *nix tools of Cygwin from gVim.
Plugins expecting a *nix shell work seamlessly. For example, I can use a
mapping of the Emmet plugin to change a url under the cursor to an HTML tag
containing the page's title as its element value. For this, Emmet retrieves
the resource behind the url via Cygwin's wget, the HTML is parsed, the page's
title is extracted and replaced into the file as an HTML <a> element. It works
like a charm.

Now to the issues with Netrw:

Issue 1)
Under Cygwin, a full file path like
C:\some\file.txt
takes often the form
/cygdrive/c/some/file.txt
The drive prefix '/cygdrive' is customizable in Cygwin by editing /etc/fstab,
see [1]. Unfortunately Netrw has '/cygdrive' hard-coded in it. This makes Netrw
to fail when trying to access a temporary file if the prefix happens to be
something different from '/cygdrive'. My Cygwin installation uses the '/mnt'
prefix, which I highly prefer over '/cygdrive'. I think this should be
automatically detected by the plugin or, at the very least, there should be a
global configuration variable to adjust it.

Issue 2)
The values of g:netrw_http_[x]cmd are not set when invoking the plugin and
Netrw complains that there is no wget installed, which is not true. Setting
these globals manually from vim's command line or in .vimrc fixes the problem
but it should work by itself if I correctly understand.

Issue 3)
After making the above corrections Netrw is able to retrieve the remote
resource with Cygwin's wget and to store it into a temp file. Inspecting the
file manually shows that the downloaded contents are actually there. However,
the deletion of the temporary file still fails because Netrw invokes
call delete("/cygdrive/c/some/tempfile")
The problem is that gVim's 'delete' expects a Windows native path. I don't know
how to get around this without modifying the plugin's source.
Note also that execution is aborted at this point and the downloaded file isn't
even loaded into the buffer, so it's not something you could just ignore.


I think issue 1 should be formally filed somewhere, I just don't know where.
As for issues 2 and 3 I'd be interested in your insights.

Thanks

[1] http://cygwin.com/cygwin-ug-net/highlights.html#ov-hi-files

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: