1 ;;; -*- lexical-binding: t -*-
3 (defun my/kill-buffers-if-deleting-last-frame (frame)
4 "Kill all buffers when closing the last frame"
5 (when (equal (list frame) (my/frame-list-ignoring-initial-frame))
6 (dolist (buffer (buffer-list))
7 (my/kill-buffer-safely buffer))))
9 (defun my/kill-buffers-not-in-frame ()
10 "Kill buffers which are not loaded into some frame"
13 (dolist (buffer (buffer-list))
14 (let* ((window (get-buffer-window buffer t))
15 (frame (window-frame window)))
16 (if (or (null frame) (not (window-live-p window)) (my/frame-initial-frame-p frame))
17 (if (my/kill-buffer-safely buffer)
18 (cl-incf kill-count)))))
19 (message "Killed %d buffers" kill-count)))
23 (defun my/frame-initial-frame-p (frame)
24 "Returns true if the given frame is the magic 'initial frame' that always exists in GUI emacs sessions"
25 (equal "initial_terminal" (terminal-name frame)))
27 (defun my/frame-list-ignoring-initial-frame ()
28 "Returns all frames except the magic 'initial frame' that always exists in GUI emacs sessions"
29 (filtered-frame-list (lambda (frame) (not (my/frame-initial-frame-p frame)))))
31 (defun my/kill-buffer-safely (buffer)
32 "Kill the buffer if it is not special or modified"
34 (not (string-match "^ " (buffer-name buffer)))
35 (not (equal "*Messages*" (buffer-name buffer)))
37 (not (buffer-modified-p buffer))
38 (null (buffer-file-name buffer))))
39 (kill-buffer buffer)))
41 (provide 'my-kill-buffers)