[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gc-buffers ad617cfb62 02/11: Add option to ignore certain
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gc-buffers ad617cfb62 02/11: Add option to ignore certain buffers |
Date: |
Sun, 27 Nov 2022 15:59:53 -0500 (EST) |
branch: elpa/gc-buffers
commit ad617cfb6200f2da3879803e91be8165b55e30fc
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>
Add option to ignore certain buffers
---
gc-buffers.el | 69 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 53 insertions(+), 16 deletions(-)
diff --git a/gc-buffers.el b/gc-buffers.el
index 2995e1d6a4..37438628aa 100644
--- a/gc-buffers.el
+++ b/gc-buffers.el
@@ -44,6 +44,9 @@
;;; Code:
+
+;;;; User Options:
+
(defgroup gc-buffers nil
"Kill garbage buffers automatically."
:group 'internal
@@ -54,18 +57,31 @@
"Functions to find garbage buffers.
Each function is called with the buffer to test, and if any of the
-functions returns non-nil, kill that buffer. The functions should not have
-any side-effect.
+functions returns t, kill that buffer. The function may also return a
+function, then that function is called with the buffer to kill or whatever
+it wants. The functions should not have any side-effect.
Warning: Putting wrong functions here may delete working buffers. For
example, never put `always' here, that would delete all buffers."
:type 'hook
:options (list #'gc-buffers-elisp-flymake))
+(defcustom gc-buffers-ignore-functions (list #'gc-buffers-ignore-visible)
+ "Functions to ignore buffers while killing.
+
+Each function is called with the buffer to test, and if any of the
+functions returns non-nil, don't kill that buffer. The functions should
+not have any side-effect."
+ :type 'hook
+ :options (list #'gc-buffers-ignore-visible))
+
(defcustom gc-buffers-delay 60
"Kill garbage buffers after idling for this many seconds."
:type 'number)
+
+;;;; Core functions:
+
;;;###autoload
(defun gc-buffers ()
"Kill garbage buffers."
@@ -75,25 +91,23 @@ example, never put `always' here, that would delete all
buffers."
(kill-buffer-query-functions nil)
(count 0))
(dolist (buffer (buffer-list))
- (when (and (not (get-buffer-window buffer 'all-frames))
- (run-hook-with-args-until-success 'gc-buffers-functions
- buffer))
- (kill-buffer buffer)
- (setq count (1+ count))))
+ (when (not (run-hook-with-args-until-success
+ 'gc-buffers-ignore-functions buffer))
+ (let ((kill-fn (run-hook-with-args-until-success
+ 'gc-buffers-functions buffer)))
+ (when kill-fn
+ (funcall (if (eq kill-fn t)
+ #'kill-buffer
+ kill-fn)
+ buffer))
+ (setq count (1+ count)))))
(when (called-interactively-p 'interactive)
(message "%s garbage buffer%s killed"
(if (zerop count) "No" (number-to-string count))
(if (> count 1) "s" ""))))))
-(defun gc-buffers-elisp-flymake (buffer)
- "Kill garbage buffers generated by `elisp-flymake-byte-compile'.
-
-Test if BUFFER is a garbage generated by `elisp-flymake-byte-compile'."
- (and (string-match-p (rx string-start " *elisp-flymake-byte-compile*"
- (zero-or-one "-" (zero-or-more digit))
- string-end)
- (buffer-name buffer))
- (not (get-buffer-process buffer))))
+
+;;;; Mode:
(defvar gc-buffers--idle-timer nil)
@@ -109,5 +123,28 @@ Test if BUFFER is a garbage generated by
`elisp-flymake-byte-compile'."
(setq gc-buffers--idle-timer
(run-with-idle-timer gc-buffers-delay t #'gc-buffers))))
+
+;;;; Buffer test functions:
+
+(defun gc-buffers-elisp-flymake (buffer)
+ "Kill garbage buffers generated by `elisp-flymake-byte-compile'.
+
+Check if BUFFER is a garbage generated by `elisp-flymake-byte-compile'."
+ (and (string-match-p (rx string-start " *elisp-flymake-byte-compile*"
+ (zero-or-one "-" (zero-or-more digit))
+ string-end)
+ (buffer-name buffer))
+ (not (get-buffer-process buffer))))
+
+
+;;;; Ignore functions:
+
+(defun gc-buffers-ignore-visible (buffer)
+ "Ignore visible buffers.
+
+Check if BUFFER is visible."
+ (get-buffer-window buffer 'all-frames))
+
+
(provide 'gc-buffers)
;;; gc-buffers.el ends here
- [nongnu] branch elpa/gc-buffers created (now a3defe8f9e), ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers 5593630e62 01/11: Add buffer killer and option to kill elisp-flymake buffers, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers bf2940e067 07/11: Add function to kill *Async Shell Command* buffers, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers a8a66f3183 04/11: Add more buffer testing functions, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers 52d45bbbde 06/11: Add COPYING, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers 1867fdcf0c 05/11: Fix typo, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers ad617cfb62 02/11: Add option to ignore certain buffers,
ELPA Syncer <=
- [nongnu] elpa/gc-buffers c73f437316 08/11: Remove gc-buffers-inactive-minibuffer, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers afacf55458 03/11: Add function to kill " *stderr of elisp-flymake-byte-compile*", ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers 7ac5ba1a89 10/11: Ignore errors in gc-buffers-functions, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers a3defe8f9e 11/11: Add .dir-locals.el, ELPA Syncer, 2022/11/27
- [nongnu] elpa/gc-buffers 53e0772891 09/11: Fix grammatical error, ELPA Syncer, 2022/11/27