On 28 January 2010 05:47, Ben Fritz <[email protected]> wrote:
> This is potentially just a misunderstanding on my part, but it looks
> like a bug at the moment so I'm posting it here.
>
> I have a few lines in my .vimrc that I've narrowed the problem down
> to. Here is the minimal .vimrc I used to test. Note how I remove my
> normal customizations from my runtime path.
>
> ====begin test .vimrc====
>
> set nocompatible
> set runtimepath-=$HOME/vimfiles
> set runtimepath-=$HOME/vimfiles/after
>
> let g:c_syntax_for_h = 1
>
> filetype indent plugin on
> syntax on
>
> autocmd Syntax c if !&diff | setlocal foldmethod=syntax | endif | call
> EchoEnv('foldmethod')
> autocmd Syntax c if !&diff | exec 'normal zR' | endif | call EchoEnv
> ('openfolds')
> autocmd BufWinEnter * if !&diff | exec 'normal zv' | endif | call
> EchoEnv('bufwinenter')
>
> function EchoEnv(event)
>  echomsg a:event.': fdm='.&fdm.' diff='.&diff.' ft='.&ft.' fdl='.&fdl
> endfu
>
> ====end test .vimrc====
>
> When I call gvimdiff on two similar .c files, the diff opens fine, but
> the first fold in the second file only is open. Without the
> BufWinEnter command, this does not happen. In other words, the "exec
> 'normal zv'" command is firing on the second file (and only the second
> file). The EchoEnv function which I added for debug confirms this:
>
> "~\My Local Data\Peer_review_files
> \SatelliteManager.c@@.main.FSA-6000.V2.0_Development.10.c" 1226L,
> 46305C
> foldmethod: fdm=diff diff=1 ft=c fdl=0
> openfolds: fdm=diff diff=1 ft=c fdl=0
> bufwinenter: fdm=diff diff=1 ft=c fdl=0
> "~\My Local Data\Peer_review_files
> \SatelliteManager.c@@.main.FSA-6000.V2.0_Development.11.c" 1227L,
> 46411C
> foldmethod: fdm=syntax diff=0 ft=c fdl=0
> openfolds: fdm=syntax diff=0 ft=c fdl=5
> bufwinenter: fdm=syntax diff=0 ft=c fdl=5
>
> It looks like somehow, for the second file, 'diff' does not get set
> until *after* the BufWinEnter autocmd event.
>
> :help diff indicates that you can override options set by a diff using
> a modeline. This indicates that modelines are processed after diff
> mode is set. :help BufWinEnter states that it fires after modelines,
> so logically it must be after diff mode gets set as well.
>
> However, as you can see from the debug output above, this is not the
> case.
>
> What's going on?

I would approach the issue from another angle: why is the first fold open
in diff mode although you opened the fold while folding was based on
syntax?

I believe this problem is what I observed some time ago: the properties
of folds are not set to state-depends-on-size when foldmethod is changed. You
can try this by opening the first of the files, setting foldmethod to syntax,
going to the first fold, opening it and then executing:
:diffsplit file2.c
The first fold in file1.c should be open.

I believe the attached patch fixes the problem. However, I did not give it
enough time to be sure that this is the optimal solution.

-- 
Best regards,
Lech Lorens

-- 
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/fold.c b/src/fold.c
index a127bf6..3af472d 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -849,10 +849,12 @@ foldUpdate(wp, top, bot)
     fold_T	*fp;
 
     /* Mark all folds from top to bot as maybe-small. */
-    (void)foldFind(&curwin->w_folds, curwin->w_cursor.lnum, &fp);
+    (void)foldFind(&curwin->w_folds, top, &fp);
     while (fp < (fold_T *)curwin->w_folds.ga_data + curwin->w_folds.ga_len
 	    && fp->fd_top < bot)
     {
+        if (wp->w_foldinvalid)
+            fp->fd_flags = FD_LEVEL;
 	fp->fd_small = MAYBE;
 	++fp;
     }

Raspunde prin e-mail lui