Answers:
如果我已经理解了这个问题,那么下面的函数可以满足您的需求:
(defun maybe-delete-frame-buffer (frame)
"When a dedicated FRAME is deleted, also kill its buffer.
A dedicated frame contains a single window whose buffer is not
displayed anywhere else."
(let ((windows (window-list frame)))
(when (eq 1 (length windows))
(let ((buffer (window-buffer (car windows))))
(when (eq 1 (length (get-buffer-window-list buffer nil t)))
(kill-buffer buffer))))))
您可以将其添加为在关闭框架时调用的钩子:
(add-to-list 'delete-frame-functions #'maybe-delete-frame-buffer)
以下是一个满足您的第一个要求的功能(经过测试,但未经过广泛测试):关闭框架时,它将杀死当前缓冲区,除非该缓冲区在另一帧中也可见。
(defun kill-buffer-when-frame-delete-dwim (frame)
"Kill current buffer unless it's visible in another frame
besides current FRAME."
(unless (delq nil (mapcar #'(lambda (x)
(memq (current-buffer)
(mapcar #'window-buffer x)))
(mapcar #'window-list
(delq frame (frame-list)))))
(kill-buffer (current-buffer))))
(add-hook 'delete-frame-functions 'kill-buffer-when-frame-delete-dwim)
我不清楚第二个要求: