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?

1 Answer 1


This is what I have in my init file :

(defun smerge-try-smerge ()
    (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©.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.