I am using next-conflict to detect is there any git conflict, using following answer: Jump to next merge conflict in project using Magit and Smerge. I experience that if I am at the end of the file/buffer and if there is a conflict in the same buffer/file, the conflict is not found. But if I switch into another buffer, or go to top of the buffer it iss found.

Is there any workaround to fix this issue?


(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)

(defun smerge-next-safe ()
    "returns t on success, nil otherwise"
  (condition-case err
      (not (smerge-next))

(require 'vc)
(defun next-conflict ()  ;; key-binding
  (let ((buffer (current-buffer)))
    (when (not (smerge-next-safe))
      (if (eq buffer (current-buffer))
          (message "No conflicts found")
        (goto-char 0)


Good idea. Here's a next-conflict function that wraps around whenever there is no more conflicted files, but the current one still has conflicts:

(defun next-conflict ()
  (let ((buffer (current-buffer)))
    (when (not (smerge-next-safe))
      (when (eq buffer (current-buffer))
        (let ((prev-pos (point)))
          (goto-char (point-min))
          (unless (smerge-next-safe)
            (goto-char prev-pos)
            (message "No conflicts found")))))))

I modified the answer you are referring to as well (it was mine answer) as such behavior is more intuitive. And changed behavior accordingly of the built-in emacs function with similar functional.

Might be worth noting that I looked at how smerge-next is defined, and it is defined with easy-mmode-define-navigation macro. As far as I look through the macro there's no way to make smerge-next wrap around the search (e.g. by changing some variable or something like that), so I open-coded the wrapping higher the stack.

  • Thanks for the update! Should I update the changes from this questions or from original answer? – alper Mar 3 at 22:53
  • 1
    @alper from the original answer, there was an additional fix that I hesitate to include here, since this question is specific to "how to modify the code from question to resolve the question". – Hi-Angel Mar 3 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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