1

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.

3

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:

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


(defun next-conflict ()
  (interactive)
  (let ((buffer (current-buffer)))
    (when (not (smerge-next-safe))
      (vc-find-conflicted-file)
      (if (eq buffer (current-buffer))
          (message "No conflicts found")
        (goto-char 0)
        (smerge-next-safe)))))
  • 1
    thank you, that's all I needed! – elmarco Aug 1 at 7:40
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.