netrw tree list produces modified buffers when refreshing

282 views
Skip to first unread message

Michal Grochmal

unread,
Jul 17, 2016, 11:37:57 PM7/17/16
to vim_dev, Charles Campbell
Hello,

Apologies if this email bounces several times, it is my first time using
googlegroups. And I am struggling with their we interface.

I believe I found a bug in the runtime/autoload/netrw.vim script (the
path is based on the repository structure). Since `netrw` is a script
originally by DrChip he is also included in the email.

The issue happens when I open Vim with the following configuration
(.vimrc):

" 3 is tree listing
let g:netrw_liststyle=3
let g:netrw_chgwin=2
let g:netrw_winsize=22

After opening Vim I perform:

:Lexplore

To open `netrw` and finally press `r` to reorder the tree listing. I
then use `:buffers!` to look at the hidden buffers created and see this:

1 #a "[No Name]" line 1
2u h + "NetrwTreeListing 1" line 1
4u%a- "NetrwTreeListing 2" line 8
5u "NetrwTreeListing" line 1

Buffer no. 2 is marked as modified which makes Vim write the file if I
perform `:wall`. The same happens with the `R` (rename) and `D`
(delete) commands.

After a while I end with dozens of `NetrwTreeListing *` files in the
current directory (I use `:wall` often).

This does not happen if I change `g:netrw_liststyle` to any other value,
i.e. the bug is specific to the tree listing.

I have seen this behaviour using the `netrw.vim` script shipped with Vim:
https://github.com/vim/vim/blob/master/runtime/autoload/netrw.vim

And also within the `netrw.vim` script available in the Vimball on
DrChip's page:
http://www.drchip.org/astronaut/vim/#NETRW

The investigation into this bug sprouted from a question on the vim
stack exchange:
http://vi.stackexchange.com/questions/8839/how-i-configure-vim-for-use-with-netrw

------

I believe I have tracked the bug and a patch is attached. Although I
believe that my solution is ugly and not the best one by far. I only
learned Vimscript some two month ago.

In the routine `s:NetrwRefresh(islocal,dirname)` I found that commenting
the following lines stopped the modified buffer from being generated:

sil! NetrwKeepj %d _
if a:islocal
NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
else
NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
endif

Therefore I managed to come up with the following solution:

sil! NetrwKeepj %d _
setl nomod
if a:islocal
NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
setl nomod
else
NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
setl nomod
endif

I have tested it, and the buffer is now correctly generated but the
modified flag is not set anymore. In essence, now all `NetrwTreeLisitng
*` buffers remain in unmodified state and are not written when I call
`:wall`.

(Adding a single `setl nomod` after the `endif` does not appear to
work.)

The patch attached contains this exact solution. It works. Yet, I
repeat, I'm not confident in my skills at editing Vimscript, and the
existence of a better solution is very likely.

Can I ask for your input on this change?

Thanks,
--
Mike Grochmal
key ID 0xC840C4F6

netrw.patch

Tony Mechelynck

unread,
Jul 18, 2016, 12:02:12 AM7/18/16
to vim_dev, vim_dev, Charles Campbell
On Mon, Jul 18, 2016 at 12:29 AM, Michal Grochmal
<groc...@member.fsf.org> wrote:
> Hello,
>
> Apologies if this email bounces several times, it is my first time using
> googlegroups. And I am struggling with their we interface.
>
> I believe I found a bug in the runtime/autoload/netrw.vim script (the
> path is based on the repository structure). Since `netrw` is a script
> originally by DrChip he is also included in the email.

Right.
Which netrw version were you using to generate you patch? The one from
Dr. Chip's Astronaut site maybe? In that case it is indeed the most
recent one but you ought to have mentioned the version number found
near the top of the file.

In the current "stable" version (156, dated 20 Apr 2016, as
distributed with Vim 7.4.2066) I find your "line 8499" at line 8465
i.e. more than 30 lines higher.


Best regards,
Tony.

Michal Grochmal

unread,
Jul 18, 2016, 6:46:12 PM7/18/16
to vim...@googlegroups.com, vim_dev, Charles Campbell
Hi,
> Which netrw version were you using to generate you patch? The one from
> Dr. Chip's Astronaut site maybe? In that case it is indeed the most
> recent one but you ought to have mentioned the version number found
> near the top of the file.
>
> In the current "stable" version (156, dated 20 Apr 2016, as
> distributed with Vim 7.4.2066) I find your "line 8499" at line 8465
> i.e. more than 30 lines higher.
>
>
> Best regards,
> Tony.

Ops, sorry for that. When I started programming SVN already existed so
i'm pretty bad with patches.

The previous patch was generated against the netrw.vim from DrChip's
website. But... after reading about patches I noticed that I generated
it in a completely wrong way. Please ignore that patch.

Allow me to start again:

The issue happens on this configuration:

vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 9 2016 09:35:51)
Included patches: 1-1910
Compiled by Arch Linux

And yes, I am running Vim (and netrw) on Arch Linux.

I can replicate the issue with *two* versions of the netrw.vim script:

Version: 156

(which it the netrw version present in the Vim repository:
https://github.com/vim/vim/blob/master/runtime/autoload/netrw.vim
And also with:

Version: 157h ASTRO-ONLY

I have now properly generated a patch for both versions of the netrw.vim
script. Both patches are attached:

netrw-156.patch: which can be run against the Vim repository.

netrw-157h.patch: which can be run against the most recent version of
the netrw.vim script from DrChip's website.

Best,
netrw-156.patch
netrw-157h.patch
Reply all
Reply to author
Forward
0 new messages