Problem changing options based on diff mode

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem changing options based on diff mode

Benjamin Fritz
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'm using:

VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jan 20 2010 14:03:25)
MS-Windows 32-bit GUI version with OLE support
Included patches: 1-343
Compiled by [hidden email]
Huge version with GUI.

--
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Problem changing options based on diff mode

Lech Lorens
On 28 January 2010 05:47, Ben Fritz <[hidden email]> 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

folds.patch (766 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problem changing options based on diff mode

Benjamin Fritz


On Jan 28, 5:43 am, Lech Lorens <[hidden email]> wrote:
>
> 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.

Yes, this is exactly what happens.

>
> 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.
>

The patch seems to fix both problems (the second file having an open
fold, and the first having one when manipulated as you suggest. Good
work!

I haven't gotten a chance yet to mess with Vim's source code, so I
don't have any opinion one way or another as to how optimal the
solution is. But it's a pretty small patch.

Unfortunately I don't have a setup to compile Vim myself at work on my
Windows machine, so I probably won't be trying it out too often, but
for what it's worth I'll keep using this patch on my Ubuntu install at
home to see if I notice anything out of place.

--
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php