bug#41868: [PATCH] Add project-clean-up command

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

bug#41868: [PATCH] Add project-clean-up command

Juri Linkov-2
>> I can't find it.  Philip, could you please resend your patch
>> with project-kill-buffers-ignore.
>
> Neither could I. I only saw your suggestion.
>
> If you really don't like the name I used, how about
> 'project-kill-buffers-ignores'?

I thought "ignore" in project-kill-buffers-ignore
is an imperative verb, but a plural noun.



Reply | Threaded
Open this post in threaded view
|

bug#41868: [PATCH] Add project-clean-up command

Dmitry Gutov
On 19.06.2020 02:18, Juri Linkov wrote:
> I thought "ignore" in project-kill-buffers-ignore
> is an imperative verb, but a plural noun.

I think it's singular (and not a real word anyway, it's our made-up lingo).

And see "project-ignores". We shouldn't be inconsistent.



Reply | Threaded
Open this post in threaded view
|

bug#41868: [PATCH] Add project-clean-up command

Eli Zaretskii
In reply to this post by Juri Linkov-2
> From: Juri Linkov <[hidden email]>
> Cc: "Philip K." <[hidden email]>,  Eli Zaretskii <[hidden email]>,
>   [hidden email],  [hidden email]
> Date: Fri, 19 Jun 2020 01:06:33 +0300
>
> Why none of recent changes were mentioned in etc/NEWS?

Why only in NEWS?  If we aim for making project.el an important
general-purpose package, its features should be in the user manual as
well.



Reply | Threaded
Open this post in threaded view
|

bug#41868: [PATCH] Add project-clean-up command

Philip K.
In reply to this post by Juri Linkov-2
Juri Linkov <[hidden email]> writes:

>>> But we already agreed on a shorter name project-kill-buffers-ignore,
>>> and Philip sent the patch that renames it.
>>
>> Could you link to it?
>
> I can't find it.  Philip, could you please resend your patch
> with project-kill-buffers-ignore.

Sure, added below.

--
        Philip K.


From 0c84b1097941b983738104b0756fd8db4a7eeac4 Mon Sep 17 00:00:00 2001
From: Philip K <[hidden email]>
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..c5301dccd3 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-kill-buffers-ignore
+  '("\\*Help\\*")
+  "Conditions for buffers `project-kill-buffers' should not kill.
+If a condition is a string, it will be interpreted as a regular
+expression, and matched against the buffer name.  If a condition
+is a function, it will be called with the buffer object, and
+returns non-nil if it matches.  Buffers that match any condition
+are \"spared\", and will hence not be killed by
+`project-kill-buffers'"
+  :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-kill-buffers-ignore'."
+  (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-kill-buffers-ignore)
+        (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

Reply | Threaded
Open this post in threaded view
|

bug#41868: [PATCH] Add project-clean-up command

Dmitry Gutov
In reply to this post by Dmitry Gutov
On 19.06.2020 02:29, Dmitry Gutov wrote:
> On 19.06.2020 02:18, Juri Linkov wrote:
>> I thought "ignore" in project-kill-buffers-ignore
>> is an imperative verb, but a plural noun.
>
> I think it's singular (and not a real word anyway, it's our made-up lingo).
>
> And see "project-ignores". We shouldn't be inconsistent.

This has been bugging me, so I did the rename anyway.

You can consider "ignores" to be a verb in indicative mood.



12