smerge-mode
doesn't always get enabled for git merge conflicts. I think this happens when I visit a file using emacsclient
which is already opened in a buffer. Something (maybe magit?) is causing the file to be auto-reverted from the filesystem, so the conflict markers appear, but unfortunately the presence of the conflict markers do not cause smerge-mode
to be activated. How can I make smerge-mode
be activated as soon as conflict markers appear in the file, regardless of whether it's freshly opened or just reverted?
Add a comment
|
1 Answer
This is what I have in my init file :
(defun smerge-try-smerge ()
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^<<<<<<< " nil t)
(require 'smerge-mode)
(smerge-mode 1))))
(add-hook 'find-file-hook 'smerge-try-smerge t)
(add-hook 'after-revert-hook 'smerge-try-smerge t)
The defun is suggested in smerge documentation, as well as the first hook. The second hook I can't remember if I saw it somewhere or just thought it was good, but all in all it seems that it Works For Me©.