GNU bug report logs -
#41868
[PATCH] Add project-clean-up command
Previous Next
Reported by: "Philip K." <philip <at> warpmail.net>
Date: Mon, 15 Jun 2020 10:02:02 UTC
Severity: normal
Tags: fixed, patch
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> On 15.06.2020 21:18, Philip K. wrote:
>
> > +(defcustom project-spare-buffers-regexps
> > + '("\\*Help\\*")
>
> Perhaps also call this project-buffer-spare-conditions? Or something
> like that. Point is, no tie the name to regexps, for easy extension into
> having functions in that list as well.
Renamed it an implemented support for predicates too.
> > + "List of regular expressions to be ignored by `project-clean-up'."
>
> Forgotten reference to the previous name.
There was also some superfluous code from an attempt to reimplement
yes-or-no-p with a third option I removed. Also fixed an inconsistency,
where the prompt would tell the user that more buffers would be killed
that would actually be, depending on the value of
project-buffer-spare-conditions.
(naively) Hoping everything it ok this time.
--
Philip K.
[0001-Add-project-kill-buffers-command.patch (text/x-diff, inline)]
>From 20ab9f1f8fe603e8ea8fe24a7d0e1fdd60be08bb Mon Sep 17 00:00:00 2001
From: Philip K <philip <at> warpmail.net>
Date: Fri, 12 Jun 2020 23:37:51 +0200
Subject: [PATCH] Add project-kill-buffers command
---
lisp/progmodes/project.el | 41 +++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index f3df44fa7b..50155e55dd 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -744,6 +744,47 @@ project-compile
(default-directory (project-root pr)))
(compile command comint)))
+(defcustom project-spare-buffers-conditions
+ '("\\*Help\\*")
+ "List of conditions to be ignored by `project-kill-buffers'.
+If a condition is a string, it will be interpreted as a regular
+expression. If the buffer name matches the regular expresion, the
+buffer will not be killed. If a contition is a function, it will
+be called with the buffer object. If it returns a non-nil value,
+the buffer will not be killed."
+ :type '(repeat (choice regexp function))
+ :version "28.1")
+
+(defun project--buffer-list (pr)
+ "Return a list of all buffers in project PR."
+ (let ((root (project-root pr)) bufs)
+ (dolist (buf (buffer-list))
+ (let ((filename (or (buffer-file-name buf)
+ (buffer-local-value 'default-directory buf))))
+ (when (and filename (file-in-directory-p filename root))
+ (push buf bufs))))
+ (nreverse bufs)))
+
+;;;###autoload
+(defun project-kill-buffers ()
+ "Kill all live buffers of a project.
+Certain buffers may be ignored, depending on the value of
+`project-spare-buffers-conditions'."
+ (interactive)
+ (let* ((pr (project-current t)) bufs)
+ (dolist (buf (project--buffer-list pr))
+ (unless (seq-some
+ (lambda (c)
+ (cond ((stringp c)
+ (string-match-p c (buffer-name buf)))
+ ((functionp c)
+ (funcall c buf))))
+ project-spare-buffers-conditions)
+ (push buf bufs)))
+ (when (yes-or-no-p (format "Kill %d buffers in %s? "
+ (length bufs) (project-root pr)))
+ (mapc #'kill-buffer bufs))))
+
;;; Project list
--
2.20.1
This bug report was last modified 4 years and 282 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.