summaryrefslogtreecommitdiff
path: root/modules/diff-config.el
blob: 382b2250884711e240cebb5ae531ac7831f580c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; diff-config.el --- diff Configuration  -*- lexical-binding: t; coding: utf-8; -*-
;; author Craig Jennings <c@cjennings.net>

;;; Commentary:

;; I've configured Ediff for a clean and efficient diff experience.

;; • Ediff will use a plain control window, horizontal splits, ignore whitespace, and only highlight the current change.
;; • A single keymap under "C-c D" has bindings:
;;   - ediff-files (f)
;;   - ediff-buffers (b)
;;   - ediff-revision (r)
;;   - ediff-directories (D)
;; • An Ediff hook that remaps j/k to next/previous differences for easier navigation
;; • The winner-mode functionality ensures window layouts are restored after quitting Ediff

;; Note: Here's a highly useful setup for configuring ediff.
;; https://oremacs.com/2015/01/17/setting-up-ediff/

;;; Code:

(use-package ediff
  :ensure nil ;; built-in
  :defer t
  :custom
  (ediff-window-setup-function  'ediff-setup-windows-plain)
  (ediff-split-window-function  'split-window-horizontally)
  (ediff-diff-options            "-w")
  (ediff-highlight-all-diffs    nil)
  :bind-keymap ("C-c D" . cj/ediff-map)
  :init
  ;; adding this to a hook to make sure ediff is loaded due to :defer
  (defvar cj/ediff-map
	(let ((m (make-sparse-keymap)))
	  (keymap-set m "f" #'ediff-files)        ; C-c D f
	  (keymap-set m "b" #'ediff-buffers)      ; C-c D b
	  (keymap-set m "r" #'ediff-revision)     ; C-c D r
	  (keymap-set m "D" #'ediff-directories)  ; C-c D D
	  m)
	"Prefix map for quick Ediff commands under C-c D.")
  :config
  (defun cj/ediff-hook ()
	"Use j/k to navigate differences in Ediff."
	(ediff-setup-keymap)  ;; keep the defaults…
	(keymap-set ediff-mode-map "j" #'ediff-next-difference)
	(keymap-set ediff-mode-map "k" #'ediff-previous-difference))

  (add-hook 'ediff-mode-hook               #'cj/ediff-hook)
  (add-hook 'ediff-after-quit-hook-internal #'winner-undo))


(provide 'diff-config)
;;; diff-config.el ends here