Atlassian SourceTree and Emacs Ediff

Since I've been doing a good amount of code reviews lately, I decided to give the Atlassian SourceTree tool a spin. Of course, I still need Emacs and EDiff to be productive, so I had to come up with some hacks to get that to integrate properly. First, I repurposed some of the hooks that I have, which makes EDiff nice and wide and can take advantage of proper side-by-side diffing. In my ~/.emacs, I have something like

(if window-system
    (progn
      (add-hook 'ediff-before-setup-hook
                'new-frame)

      (add-hook 'ediff-quit-hook
                'delete-frame)

      (add-hook 'ediff-startup-hook
                '(lambda ()
                   (set-frame-size (selected-frame) 300 80)
                   (set-face-attribute 'default (selected-frame) :height 130)
                   (raise-frame (selected-frame))
                   ))
      ))

I also have a few convenience things in my ~/.emacs, which are not absolutely necessary:

(global-set-key "\C-xv-" 'vc-ediff)
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-horizontally)

 

For the SourceTree tool, now it's just a matter of sending the appropriate emacs or emacsclient command. Of course, you have to make sure to start emacs-server in your running Emacs, if you wish to use one single instance of Emacs, and emacsclient. In my SourceTree Preferences, I added an external differ, with the Other command being /usr/local/bin/emacsclient, and the argument

--eval "(ediff-files \"$LOCAL\" \"$REMOTE\")"

 

That's it! Now that I click on External Diff (Command-D), it launches a new, wide Emacs frame with a side-by-side EDiff. Super convenient, and easy to use (n for next diff, p for previous, q to quit, ? to see more commands).