I sometimes miss a feature in Emacs where I could make a diff of two files (using Emacs built-in dired-diff
command, bound to =
in Dired, or abo-abo’s diff trick, which I have bound to e
in Dired), but have the diff persist (as in, save it to a file). Technically, I can do this, of course, by just calling write-file
and saving it to a file (preferably with a .diff
extension so that it will open in Diff mode automatically), but sometimes I prefer to save things in my Org-mode file, along with my notes related to the project I’m working on.
It turns out that Org-mode has me covered, although there is one minor caveat here. I can say
#+begin_src diff diff -ur /mem/aqq /mem/bum --- /mem/aqq 2018-10-29 08:40:07.639993680 +0100 +++ /mem/bum 2018-10-29 08:40:15.329993584 +0100 @@ -1,3 +1,3 @@ lorem ipsum -dolor +sit amet Diff finished. Mon Oct 29 08:40:20 2018 #+end_src
but if I edit this source block using C-c '
(org-edit-special
) and then save it e.g. using C-c '
(org-edit-src-exit=), Org-mode enforces indentation of two spaces. This, however, fools Diff-mode’s font-locking features and I lose the coloring of the diff.
There is a way out of it, though. Either you can be careful not to run org-edit-special
on the diff block, or you can set org-edit-src-content-indentation
to 0.
I know that because I asked on the Org-mode mailing list, and I got a few helpful responses. Make sure to read them (and the docstrings of the mentioned variables) if that is of interest for you.
CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode