From 690ec65a30bea59b77a4cec1c21814b077a04c13 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 13 Nov 2020 09:40:43 -0800 Subject: Make the diff server function clean up after itself --- oni-ediff.el | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'oni-ediff.el') diff --git a/oni-ediff.el b/oni-ediff.el index cb52386..1d6d860 100644 --- a/oni-ediff.el +++ b/oni-ediff.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2020.1106.164913 +;; Version: 2020.1113.093948 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -52,9 +52,23 @@ (pcase files ((and `((,fileB) (,fileA) (,command)) (guard (string= (file-name-nondirectory command) "diff"))) - (select-frame-set-input-focus (selected-frame)) - (ediff-files (expand-file-name fileA) - (expand-file-name fileB)) + (let* ((file-a-path (expand-file-name fileA)) + (file-b-path (expand-file-name fileB)) + (file-a-opened-p (find-buffer-visiting fileA)) + (file-b-opened-p (find-buffer-visiting fileB)) + cleanup-function) + (setq cleanup-function + (lambda () + (remove-hook 'ediff-cleanup-hook cleanup-function) + (when (not file-a-opened-p) + (kill-buffer (find-buffer-visiting file-a-path))) + (when (not file-b-opened-p) + (kill-buffer (find-buffer-visiting file-b-path))) + (delete-process proc))) + (select-frame-set-input-focus (selected-frame)) + (ediff-files (expand-file-name fileA) + (expand-file-name fileB)) + (add-hook 'ediff-cleanup-hook cleanup-function)) nil) (_ (message "Got args: \"%s\"" (list files proc nowait)) -- cgit v1.2.3-54-g00ecf