On 2018-09-13, Christian Brabandt wrote:
> On Mi, 12 Sep 2018, Gary Johnson wrote:
>
> > On 2018-09-12, Bram Moolenaar wrote:
> > > Gary Johnson wrote:
> > >
> > > > When I diff a syntax-highlighted buffer, the diff highlighting often
> > > > conflicts with the syntax highlighting so that some text has the
> > > > same foreground and background colors and becomes impossible to
> > > > read.
> > > >
> > > > I have worked around this problem with the following autocommand.
> > > >
> > > > au FilterWritePost * if &diff | setlocal syn=OFF | endif
> > > >
> > > > With the new internal diff, this doesn't seem to be working anymore.
> > > > That makes sense since the internal diff doesn't need to write any
> > > > files, but now we don't seem to have a hook for changing settings
> > > > when diff is enabled.
> > > >
> > > > What would be nicest is a pair of hooks (autocommand events) that
> > > > would be triggered when a buffer entered and left diff mode.
> > > >
> > > > Any thoughts on this?
> > >
> > > How about using an OptionSet autocommand? I haven't tried this:
> > >
> > > au OptionSet diff if &diff | setlocal syn=OFF | endif
> >
> > In some but not in all cases. For example, if I run vimdiff as part
> > of the "git difftool" command, the OptionSet autocommand is not
> > triggered.
> >
> > I also tried BufWinEnter, but it didn't help.
>
> That is most likely because OptionSet is not run on startup. However, if
> you add into your .vimrc something like this:
>
> if &diff | setlocal syn= |endif
>
> in addition to the optionset auto command, shouldn't this than work?
> E.g. on startup simply check if the diff option is already set and if
> so, disable syntax highlighting?
It's more complicated than that. I set syn according to file type,
so I can't it according to just the state of &diff when ~/.vimrc is
sourced.
syntax manual
let no_syntax_filetypes = [ 'c', 'cpp', 'man', 'netrw', 'python', 'vim' ]
au FileType * if !empty(expand("<amatch>"))
\ | if !count(no_syntax_filetypes, expand("<amatch>"))
\ | let b:syn="ON"
\ | if !&diff
\ | setlocal syntax=ON
\ | endif
\ | else
\ | syn clear
\ | if exists("b:current_syntax")
\ | unlet b:current_syntax
\ | endif
\ | endif
\ | endif
There are three events that can cause syn to change state:
Entering diff mode
Exiting diff mode
Detecting the buffer file type
The FileType event catches the last event. I use a command to exit
diff mode, which handles the second event. The problem is the first
event, determining when diff mode has been entered. This has always
been difficult. I had a solution that worked for quite a while and
I've forgotten some of the reasons for doing what I've done, but it
took a good bit of fiddling to get it to work. My ~/.vimrc is
littered with commented-out code that failed some corner case. Now
that the internal diff functionality has changed the diff behavior,
I'm afraid it's going to take some time to get it to work again.
I won't be able to look at this for the next week, so if I don't
respond again for a while it's not for lack of interest.
Regards,
Gary
--
--
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.