I found out that magit-ediff-dwim cannot "read my mind" in a diff buffer when the point is on a hunk.

Intuitively, I would expect this command to need only two things to guess what I mean: a file (e.g. the file of the hunk at point) and either a revision or a range. In a revision buffer, magit-ediff-dwim correctly guesses which revision ediff should use.

When visiting arbitrary diffs however, the function does not guess that "what I mean" is starting an ediff session using the same range as the one which defines the diff buffer.

Some scenarios to reproduce:

  • d r foo..bar will spawn a diff buffer showing changes between revisions foo and bar;
  • d d when point is on branch baz in the refs buffer will spawn a diff buffer showing changes from the current branch to baz;
  • d d in the log buffer when the region spans commits foo to bar will spawn a diff buffer showing changes between revisions foo and bar.

In each of these situations, if I set the point on a hunk and call magit-ediff-dwim, the function fails to read my mind.

I poked around magit-diff.el and magit-ediff.el and found that I could help magit read my mind by adding the following to magit-diff--dwim:

@@ -616,6 +616,8 @@ If no DWIM context is found, nil is retu
     (cons 'commit magit-buffer-refname))
    ((derived-mode-p 'magit-revision-mode)
     (cons 'commit (car magit-refresh-args)))
+   ((derived-mode-p 'magit-diff-mode)
+    (nth 0 magit-refresh-args))
       ([* unstaged] 'unstaged)

Disclaimer: I am not an E?Lisp developer by any means. I just threw the above together after looking up a few symbols' documentation or messageing their value when trying to wrap my head around what was happening.

Onto questions.

  1. Am I missing something that would explain why magit-ediff-dwim should not read my mind in diff buffers, although it can in rev buffers?
  2. Is this worth creating an issue on the Github tracker?
  3. Is the patch above sound? I figure maybe it is not appropriate to poke around magit-refresh-args, or maybe another case could be added to the magit-section-case switch below.

Version: 20151118.241 from MELPA.

Additional disclaimer: sorry if I sound like I am complaining - magit is a wonderful piece of software that makes version control a very pleasant experience.

  • It seems I have now placed the "don't use the issue tracker to ask questions" prominently enough. But it also seems to have had too big an effect on you in this case - here it would have been better to go directly to the github issue tracker. I would consider this either a feature request or a bug report, hell, there's code, so it could have been a pull request (though I suspect this will be a bit more involved than adding these two lines). I'll try to have a look in a few days. (And I think it's okay to keep this open in the mean time, and that there's no need to also open a feature request.)
    – tarsius
    Nov 18, 2015 at 19:30

1 Answer 1


The addition you suggested does the job just fine. I've added them now. Sorry for the delay. It would of course be nice if this also jumped to the correct change, but that isn't implemented yet (see issue #1566).

  • Never mind the delay, thank you for taking the time to add this :) If the lack of jump ends up itching, I might start poking around again (although I suspect this itch will feel pretty minor compared to the one which got me to ask this question).
    – Peniblec
    Dec 13, 2015 at 11:03

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.