Function: majutsu-ediff-buffers
majutsu-ediff-buffers is a macro defined in majutsu-ediff.el.
Signature
(majutsu-ediff-buffers A B &optional C SETUP QUIT FILE)
Documentation
Run Ediff on two or three buffers.
A, B and C have the form (GET-BUFFER CREATE-BUFFER). If GET-BUFFER returns a non-nil value, that buffer is used and not killed when exiting. Otherwise CREATE-BUFFER must return a buffer and that is killed on exit.
SETUP is called after Ediff setup. QUIT is added to quit hook. If FILE is non-nil, perform a merge with result written to FILE.
Source Code
;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-ediff.el
;;; Buffer Management
(defmacro majutsu-ediff-buffers (a b &optional c setup quit file)
"Run Ediff on two or three buffers.
A, B and C have the form (GET-BUFFER CREATE-BUFFER). If GET-BUFFER
returns a non-nil value, that buffer is used and not killed when exiting.
Otherwise CREATE-BUFFER must return a buffer and that is killed on exit.
SETUP is called after Ediff setup. QUIT is added to quit hook.
If FILE is non-nil, perform a merge with result written to FILE."
(let (get make kill (char ?A))
(dolist (spec (list a b c))
(if (not spec)
(push nil make)
(pcase-let ((`(,g ,m) spec))
(let ((b (intern (format "buf%c" char))))
(push `(,b ,g) get)
(push `(or ,b ,m) make)
(push `(unless ,b
(let ((var ,(if (and file (= char ?C))
'ediff-ancestor-buffer
(intern (format "ediff-buffer-%c" char)))))
(ediff-kill-buffer-carefully var)))
kill))
(cl-incf char))))
(setq get (nreverse get))
(setq make (nreverse make))
(setq kill (nreverse kill))
(let ((mconf (gensym "conf"))
(mfile (gensym "file")))
`(majutsu-with-toplevel
(let ((,mconf (current-window-configuration))
(,mfile ,file)
,@get)
(ediff-buffers-internal
,@make
(list ,@(and setup (list setup))
(lambda ()
(setq-local ediff-quit-merge-hook nil)
(setq-local ediff-quit-hook
(list
,@(and quit (list quit))
(lambda ()
,@kill
(let ((majutsu-ediff-previous-winconf ,mconf))
(run-hooks 'majutsu-ediff-quit-hook)))))))
(pcase (list ,(and c t) (and ,mfile t))
('(nil nil) 'ediff-buffers)
('(nil t) 'ediff-merge-buffers)
('(t nil) 'ediff-buffers3)
('(t t) 'ediff-merge-buffers-with-ancestor))
,mfile))))))