2020-05-11 Diffing and font-lock

I often work with diffs in Emacs. I usually do that within Magit, which highlights diffs in the usual way (highlighting deleted lines with reddish background, inserted lines with greenish background, and the deleted/inserted characters within these lines with slightly more prominent versions of the same colors). However, I sometimes use plain Emacs diff (e.g. to compare two fles not kept in Git), and I noticed an annoying thing: diff’s font-lock is applied on top of the usual font-lock, depending on the files’ syntax. While in general this seems resonable, in the case of LaTeX files in AUCTeX (where the font lock colors are especially diverse) this makes the diff completely unreadable. I was pretty sure that disabling the syntax font-lock would reduce the visual noise of the diffs.

Knowing that font-lock is one of the darker corners of Emacs, I didn’t even try to solve this issue myself and asked the help-gnu-emacs mailing list about it. The problem was, I apparently chose the subject line of my email poorly enough that I didn’t get the answer… (Well, I did, but something like two hours after I found the answer myself!)

So, I decided to tackle the problem myself. I started with looking for variables matching the regex diff.*font – and it turned out to be enough! There is the diff-font-lock-syntax variable, whose docstring reveals a number of ways Emacs can try syntax highlighting in diff buffers in a variety of ways, with different speed and accuracy characteristics. For me, the most important thing was that I could choose between the default t and nil, which turned off the syntax-based font-lock in diff buffers entirely. (Incidentally, I noticed that it didn’t work in some modes anyway. Go figure.)

Happy diffing!

CategoryEnglish, CategoryBlog, CategoryEmacs