3

When I am resolving merge conflicts with Magit and Smerge, is there a way for me to cycle through all merge conflicts in the project? Currently I can only move through them one file at a time.

I wrote something like this as as utility but it's not great:

(defun jump-to-first-merge-conflict ()
  (interactive)
  (magit-status)
  (beginning-of-buffer)
  (magit-section-forward-sibling)
  (magit-section-forward-sibling)
  (magit-section-forward)
  (execute-kbd-macro (kbd "<return>")))

It would be nice if I could just use smerge in a project context, instead of a file context.

5

Just 7 hours ago to Smerge was added a new command to do exactly that. Now you can use M-x smerge-vc-next-conflict to either jump to the next conflict in focused buffer or to the next conflicted file in the repository that the file belongs to.

Don't forget to use (require 'smerge-mode) for this function to appear.


For those who can't for some reason upgrade Emacs, I can share an analogous function next-conflict I've been using:

(require 'vc)

(defun smerge-next-safe ()
  "Return t on success, nil otherwise"
  (ignore-errors (not (smerge-next))))

(defun next-conflict ()
  (interactive)
  (when (not (smerge-next-safe))
    (vc-find-conflicted-file)
    ;; At this point, the caret will only be at a conflict marker if the file did not
    ;; correspond to an opened buffer. Otherwise, we need to jump to a marker explicitly.
    (unless (looking-at "^<<<<<<<")
      (let ((prev-pos (point)))
        (goto-char (point-min))
        (unless (smerge-next-safe)
          (goto-char prev-pos)
          (message "No conflicts found"))))))
8
  • 1
    thank you, that's all I needed! – elmarco Aug 1 '19 at 7:40
  • I am having Symbol’s function definition is void: vc-find-conflicted-file error – alper Aug 27 '20 at 19:53
  • @alper try evaluating (require 'vc) to see if that helps. But worth noting that this is odd, because for me it's available even if I run emacs -Q to not load any configs. What Emacs version you have? – Hi-Angel Aug 28 '20 at 6:39
  • 1
    I am using Emacs 26.3, seems like (require 'vc) fixed the issue – alper Aug 28 '20 at 11:13
  • 1
    Good idea, done – Hi-Angel Feb 15 at 18:10
1

Magit does not support that currently, but I have just added a note to a related feature request.

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.