Thanks Tony.

It turns out that netrw is the culprit, and that the issue does not only apply to the cindent option. Netrw attempts to save, change and restore the following local buffer options:

autoindent
cindent
cinoptions
comments
copyindent
formatoptions
swapfile        
textwidth

But I am finding that under some conditions (see my original post) these values are not restored, and instead are retaining the values that were set by netrw.

To reliably preserve these options when using file type plugins and netrw, I am now taking a more defensive approach, placing the local buffer settings before checking to see if the plugin has been executed, like this:

set cindent sw=4 ts=4 swapfile
if exists("b:did_java_vim")
   finish
 endif
 let b:did_java_vim = 1
" other plugin commands follow...

Note that netrw turns off the swapfile option, so to preserve the possibility of file recovery it must be explicitly turned on in the file type plugins.

-Mark


A.J.Mechelynck wrote:
Mark S. Williams wrote:
I think I've uncovered an odd bug involving Netrw and the cindent local buffer option for Java files, where cindent is unset under certain conditions.

To track down the bug I removed all my Java file type plugins and created a new Java file type plugin called java.vim which contains only the following:

if exists("b:did_java_vim")
  finish
endif
let b:did_java_vim = 1
setlocal cindent


There are two scenarios that can reproduce the bug:

Scenario #1
-----------
1. Start vim in a dir with Foo.java
2. :E and select Foo.java
3. :setl  cindent is set.
4. :E and select Foo.java again.
5. :setl and cindent is not set.

Scenario #2
-----------
1. Start vim in a dir with Foo.java and Bar.java
2. :E and select Foo.java
3. :setl  cindent is set.
4. :E and select Bar.java
5. :setl  cindent is set.
6. :2b to return to Foo.java
7. :setl and cindent is not set.

It seems the the bug involves Netrw, I can't reproduce it when I open files with :e.

Quite a puzzler. Can anyone else reproduce this one?

Thanks in advance,
-Mark



To check which script last set the option, use ":verbose setl cindent?" (without quotes, but with the question mark). If it does mention netrw, check near the top of the netrw script which version of netrw you're running. You may be able to obtain a newer version from vim-online or from Dr. Chip's site.


Best regards,
Tony.


Reply via email to