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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41868 in the body.
You can then email your comments to 41868 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Mon, 15 Jun 2020 10:02:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
"Philip K." <philip <at> warpmail.net>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 15 Jun 2020 10:02:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi,
I wanted to propose a command for project.el to kill all opened buffers
in a project, called when one finishes working on some specific
code-base. I gave it the name "project-clean-up", but maybe it should be
renamed? I have been using it in my local emacs branch for about a week,
and have found it to be useful.
One issue I ran into is that a buffer might be falsely associated with a
project, such as *Help*. That's why I added an user option
project-dont-clean-regexps to contain a list of regular expression of
what buffer names to spare. The reason I couldn't just stick to checking
the value of buffer-file-name is that Dired, VC, etc. buffers don't get
recognized. There might be a better way to do this, but I'm not sure if
it's worth the effort.
And it might be worth considering to add a prompt, to ask the user if
they actually want to kill all the buffers.
--
Philip K.
[0001-Add-project-clean-up-command.patch (text/x-diff, inline)]
From d7d4127cc561b3f2d1650d19a3fb58895a4cabd1 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-clean-up command
---
lisp/progmodes/project.el | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index f3df44fa7b..9e55f3594c 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -744,6 +744,35 @@ project-compile
(default-directory (project-root pr)))
(compile command comint)))
+(defcustom project-dont-clean-regexps
+ '("\\*Help\\*")
+ "List of regular expressions to be ignored by `project-clean-up'."
+ :type '(repeat regexp))
+
+(defun project--list-buffers (pr)
+ "Return a list of all buffers in project PR."
+ (let ((root (project-root pr))
+ bufs)
+ (dolist (buf (buffer-list))
+ (when-let* ((path (or (buffer-file-name buf)
+ (buffer-local-value 'default-directory buf)))
+ (true (file-truename path)))
+ (when (file-in-directory-p true root)
+ (push buf bufs))))
+ bufs))
+
+;;;###autoload
+(defun project-clean-up ()
+ "Kill all opened buffers in a project."
+ (interactive)
+ (let* ((pr (project-current t)))
+ (dolist (buf (project--list-buffers pr))
+ (let ((match (mapcar (lambda (re)
+ (and (string-match-p re (buffer-name buf)) t))
+ project-dont-clean-regexps)))
+ (unless (memq t match)
+ (kill-buffer buf))))))
+
;;; Project list
--
2.20.1
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Mon, 15 Jun 2020 11:06:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 41868 <at> debbugs.gnu.org (full text, mbox):
"Philip K." <philip <at> warpmail.net> writes:
> I wanted to propose a command for project.el to kill all opened buffers
> in a project, called when one finishes working on some specific
> code-base.
Thanks, just some minor nits from me.
[...]
> And it might be worth considering to add a prompt, to ask the user if
> they actually want to kill all the buffers.
Something like "Kill <N> buffers under <root>? "?
[...]
> +(defcustom project-dont-clean-regexps
> + '("\\*Help\\*")
> + "List of regular expressions to be ignored by `project-clean-up'."
> + :type '(repeat regexp))
This needs a :version tag.
> +(defun project--list-buffers (pr)
> + "Return a list of all buffers in project PR."
> + (let ((root (project-root pr))
> + bufs)
> + (dolist (buf (buffer-list))
> + (when-let* ((path (or (buffer-file-name buf)
^^^^
Nit: Paths in Emacs are directory lists, whereas this is a file name.
> + (buffer-local-value 'default-directory buf)))
> + (true (file-truename path)))
Doesn't file-in-directory-p do this for us?
> + (when (file-in-directory-p true root)
> + (push buf bufs))))
> + bufs))
Maybe the list should be returned in the same order as (buffer-list), by
using either nreverse or seq-filter?
> +;;;###autoload
> +(defun project-clean-up ()
> + "Kill all opened buffers in a project."
^^^^^^
live?
> + (interactive)
> + (let* ((pr (project-current t)))
Nit: No need for let*.
> + (dolist (buf (project--list-buffers pr))
> + (let ((match (mapcar (lambda (re)
> + (and (string-match-p re (buffer-name buf)) t))
> + project-dont-clean-regexps)))
> + (unless (memq t match)
> + (kill-buffer buf))))))
Nit: AKA
(unless (seq-some (lambda (re)
(string-match-p re (buffer-name buf)))
project-dont-clean-regexps)
...)
Thanks,
--
Basil
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Mon, 15 Jun 2020 11:33:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 41868 <at> debbugs.gnu.org (full text, mbox):
Thanks for the notes, just a few questions/justifications below:
"Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>> And it might be worth considering to add a prompt, to ask the user if
>> they actually want to kill all the buffers.
>
> Something like "Kill <N> buffers under <root>? "?
Yes, I'll propose something like that in my next patch.
>> + (when (file-in-directory-p true root)
>> + (push buf bufs))))
>> + bufs))
>
> Maybe the list should be returned in the same order as (buffer-list), by
> using either nreverse or seq-filter?
Is there any benifit to this, or is this just a matter of not disrupting
expectations? My thought was that this was more like a set than a proper
list (despite the function name).
>> + (dolist (buf (project--list-buffers pr))
>> + (let ((match (mapcar (lambda (re)
>> + (and (string-match-p re (buffer-name buf)) t))
>> + project-dont-clean-regexps)))
>> + (unless (memq t match)
>> + (kill-buffer buf))))))
>
> Nit: AKA
>
> (unless (seq-some (lambda (re)
> (string-match-p re (buffer-name buf)))
> project-dont-clean-regexps)
> ...)
Would this require adding a "(require 'seq)" to the top? I always kind
of hesistate in adding new dependencies in patches, but if it's already
loaded, it would look better this way.
--
Philip K.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Mon, 15 Jun 2020 11:39:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 41868 <at> debbugs.gnu.org (full text, mbox):
"Philip K." <philip <at> warpmail.net> writes:
> Thanks for the notes, just a few questions/justifications below:
>
> "Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>
>>> + (when (file-in-directory-p true root)
>>> + (push buf bufs))))
>>> + bufs))
>>
>> Maybe the list should be returned in the same order as (buffer-list), by
>> using either nreverse or seq-filter?
>
> Is there any benifit to this, or is this just a matter of not disrupting
> expectations? My thought was that this was more like a set than a proper
> list (despite the function name).
I just thought it might be more natural to process buffers in their
usual order, in case it makes a difference in any kill-buffer-related
hooks. It probably doesn't matter much.
>>> + (dolist (buf (project--list-buffers pr))
>>> + (let ((match (mapcar (lambda (re)
>>> + (and (string-match-p re (buffer-name buf)) t))
>>> + project-dont-clean-regexps)))
>>> + (unless (memq t match)
>>> + (kill-buffer buf))))))
>>
>> Nit: AKA
>>
>> (unless (seq-some (lambda (re)
>> (string-match-p re (buffer-name buf)))
>> project-dont-clean-regexps)
>> ...)
>
> Would this require adding a "(require 'seq)" to the top? I always kind
> of hesistate in adding new dependencies in patches, but if it's already
> loaded, it would look better this way.
A lot of seq.el functions are autoloaded, including seq-some.
Thanks,
--
Basil
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Mon, 15 Jun 2020 12:29:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 15.06.2020 13:00, Philip K. wrote:
> I wanted to propose a command for project.el to kill all opened buffers
> in a project, called when one finishes working on some specific
> code-base. I gave it the name "project-clean-up", but maybe it should be
> renamed?
I've just looked it up, and Projectile has a command called
project-kill-buffers. Perhaps follow its example?
https://github.com/bbatsov/projectile/blob/33bc91e7518fb8cecd89580f16e0ac21799de2c2/projectile.el#L3642
I somewhat prefer the explicit naming. Looking at it, you won't mistake
it for a command that removes build artefacts, or "tidies up" the code,
for instance.
> I have been using it in my local emacs branch for about a week,
> and have found it to be useful.
Sounds useful indeed!
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Mon, 15 Jun 2020 18:19:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 41868 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> On 15.06.2020 13:00, Philip K. wrote:
>> I wanted to propose a command for project.el to kill all opened buffers
>> in a project, called when one finishes working on some specific
>> code-base. I gave it the name "project-clean-up", but maybe it should be
>> renamed?
>
> I've just looked it up, and Projectile has a command called
> project-kill-buffers. Perhaps follow its example?
>
> https://github.com/bbatsov/projectile/blob/33bc91e7518fb8cecd89580f16e0ac21799de2c2/projectile.el#L3642
>
> I somewhat prefer the explicit naming. Looking at it, you won't mistake
> it for a command that removes build artefacts, or "tidies up" the code,
> for instance.
I changed the name to project-kill-buffer in the patch below. It kind of
feels like a ripoff now, but there probably aren't that many way to
implement the idea either.
Hope I didn't miss any of the issues brought up.
--
Philip K.
[0001-Add-project-kill-buffers-command.patch (text/x-diff, inline)]
From 35c10566382dd31442fd59bf8e3ee695dc595386 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 | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index f3df44fa7b..6fe5dfa880 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -744,6 +744,39 @@ project-compile
(default-directory (project-root pr)))
(compile command comint)))
+(defcustom project-spare-buffers-regexps
+ '("\\*Help\\*")
+ "List of regular expressions to be ignored by `project-clean-up'."
+ :type '(repeat regexp)
+ :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."
+ (interactive)
+ (let* ((pr (project-current t))
+ (bufs (project--buffer-list pr)))
+ (with-temp-buffer
+ (setf (buffer-name) " *project buffer list*")
+ (when (yes-or-no-p (format "Kill %d buffers in %s? "
+ (length bufs) (project-root pr)))
+ (dolist (buf bufs)
+ (unless (seq-some (lambda (re)
+ (string-match-p re (buffer-name buf)))
+ project-spare-buffers-regexps)
+ (kill-buffer buf)))))))
+
;;; Project list
--
2.20.1
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Mon, 15 Jun 2020 20:52:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 15.06.2020 21:18, Philip K. wrote:
> I changed the name to project-kill-buffer in the patch below. It kind of
> feels like a ripoff now, but there probably aren't that many way to
> implement the idea either.
Indeed. And, well, following the example in a few (functional) names
shouldn't be considered a fault WRT copyright.
Taking pains to be "different" won't serve anyone either.
> +(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.
> + "List of regular expressions to be ignored by `project-clean-up'."
Forgotten reference to the previous name.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 00:03:03 GMT)
Full text and
rfc822 format available.
Message #26 received at 41868 <at> debbugs.gnu.org (full text, mbox):
>> +(defcustom project-spare-buffers-regexps
>> + '("\\*Help\\*")
>
> Perhaps also call this project-buffer-spare-conditions?
I think the suffix ‘-regexps’ is fine. The problem is that
the word “spare” has no reference to the related command name
‘project-kill-buffers’. Maybe better would be something like
‘project-kill-buffers-ignore-regexps’ or
> Or something like that. Point is, no tie the name to regexps, for easy
> extension into having functions in that list as well.
For functions it's easy to add a separate variable like
‘project-kill-buffers-ignore-functions’.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 00:24:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 16.06.2020 01:49, Juri Linkov wrote:
>>> +(defcustom project-spare-buffers-regexps
>>> + '("\\*Help\\*")
>>
>> Perhaps also call this project-buffer-spare-conditions?
>
> I think the suffix ‘-regexps’ is fine. The problem is that
> the word “spare” has no reference to the related command name
> ‘project-kill-buffers’. Maybe better would be something like
> ‘project-kill-buffers-ignore-regexps’ or
"kill or spare", no? But it's not immediately obvious for non-native
speakers, sure.
>> Or something like that. Point is, no tie the name to regexps, for easy
>> extension into having functions in that list as well.
>
> For functions it's easy to add a separate variable like
> ‘project-kill-buffers-ignore-functions’.
I don't see why we wouldn't want to keep it on the same variable. It's
both easier to document, and to implement.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 06:40:01 GMT)
Full text and
rfc822 format available.
Message #32 received at submit <at> debbugs.gnu.org (full text, mbox):
[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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 10:20:01 GMT)
Full text and
rfc822 format available.
Message #35 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 16.06.2020 00:50, Philip K. wrote:
> (naively) Hoping everything it ok this time.
Thanks! It's looking good.
Let's also hear what Juri thinks. To address one of his concerns, the
var could be renamed to project-kill-buffers-spare-conditions.
One added benefit of this is it would be immediately clear from the name
that it only affects a specific command.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 10:53:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 41868 <at> debbugs.gnu.org (full text, mbox):
"Philip K." <philip <at> warpmail.net> writes:
> (naively) Hoping everything it ok this time.
Just one tiny detail from me. ;)
> +(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."
Some of the full stops aren't followed by two spaces here
(see sentence-end-double-space in Emacs' dir-locals-file).
Perhaps some of the common wording can be factored out as well
(feel free to adapt as you see fit):
"List of conditions to be ignored by `project-kill-buffers'.
Buffers under the current project that match any of these
conditions will not be killed by `project-kill-buffers'. Each
condition is either a regular expression matching a buffer name,
or a predicate function that takes a buffer object as argument
and returns non-nil if it matches."
> + (let* ((pr (project-current t)) bufs)
Nit: No need for let*.
Thanks,
--
Basil
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 14:32:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 41868 <at> debbugs.gnu.org (full text, mbox):
> From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
> Date: Tue, 16 Jun 2020 11:52:26 +0100
> Cc: 41868 <at> debbugs.gnu.org, Dmitry Gutov <dgutov <at> yandex.ru>
>
> Perhaps some of the common wording can be factored out as well
> (feel free to adapt as you see fit):
>
> "List of conditions to be ignored by `project-kill-buffers'.
The first line is too general, and could deceive. How about
Conditions for buffers `project-kill-buffers' should not kill.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 17:13:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 41868 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
>> Date: Tue, 16 Jun 2020 11:52:26 +0100
>> Cc: 41868 <at> debbugs.gnu.org, Dmitry Gutov <dgutov <at> yandex.ru>
>>
>> Perhaps some of the common wording can be factored out as well
>> (feel free to adapt as you see fit):
>>
>> "List of conditions to be ignored by `project-kill-buffers'.
>
> The first line is too general, and could deceive. How about
>
> Conditions for buffers `project-kill-buffers' should not kill.
It sounds good, so I used it in the revised patch below, together with a
few other minor improvments which Basil mentioned.
--
Philip K.
[0001-Add-project-kill-buffers-command.patch (text/x-diff, inline)]
From 2172f4d3d310d75dadf5ef0af297476e873349b8 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 | 42 +++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index f3df44fa7b..04d3b324d6 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -744,6 +744,48 @@ project-compile
(default-directory (project-root pr)))
(compile command comint)))
+(defcustom project-spare-buffers-conditions
+ '("\\*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-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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Tue, 16 Jun 2020 22:01:02 GMT)
Full text and
rfc822 format available.
Message #47 received at 41868 <at> debbugs.gnu.org (full text, mbox):
>> I think the suffix ‘-regexps’ is fine. The problem is that
>> the word “spare” has no reference to the related command name
>> ‘project-kill-buffers’. Maybe better would be something like
>> ‘project-kill-buffers-ignore-regexps’ or
>
> "kill or spare", no? But it's not immediately obvious for non-native
> speakers, sure.
>
>> For functions it's easy to add a separate variable like
>> ‘project-kill-buffers-ignore-functions’.
>
> I don't see why we wouldn't want to keep it on the same variable. It's both
> easier to document, and to implement.
Then just ‘project-kill-buffers-ignore’ should be fine: short and clear.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 01:07:02 GMT)
Full text and
rfc822 format available.
Message #50 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 16.06.2020 20:12, Philip K. wrote:
> It sounds good, so I used it in the revised patch below, together with a
> few other minor improvments which Basil mentioned.
Thank you, I pushed with some minor changes.
- Docstring further rephrased based on Basil's suggestion.
- The variable renamed to project-kill-buffers-skip-conditions, hope you
don't mind.
Should we add a key binding for it as well?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 06:47:02 GMT)
Full text and
rfc822 format available.
Message #53 received at 41868 <at> debbugs.gnu.org (full text, mbox):
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> On 16.06.2020 20:12, Philip K. wrote:
>> It sounds good, so I used it in the revised patch below, together with a
>> few other minor improvments which Basil mentioned.
>
> Thank you, I pushed with some minor changes.
>
> - Docstring further rephrased based on Basil's suggestion.
> - The variable renamed to project-kill-buffers-skip-conditions, hope you
> don't mind.
I don't mind, I just thought that I had sent a patch fixing that
already?
> Should we add a key binding for it as well?
I think 'k' in project-prefix-map would fit well, as soon as that gets
merged.
--
Philip K.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 13:05:01 GMT)
Full text and
rfc822 format available.
Message #56 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 18.06.2020 09:46, Philip K. wrote:
>> Thank you, I pushed with some minor changes.
>>
>> - Docstring further rephrased based on Basil's suggestion.
>> - The variable renamed to project-kill-buffers-skip-conditions, hope you
>> don't mind.
>
> I don't mind, I just thought that I had sent a patch fixing that
> already?
If you did, I couldn't find it. Sorry.
>> Should we add a key binding for it as well?
>
> I think 'k' in project-prefix-map would fit well, as soon as that gets
> merged.
Sounds good.
Unless we also wanted a project-scoped version of kill-buffer?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 14:12:02 GMT)
Full text and
rfc822 format available.
Message #59 received at 41868 <at> debbugs.gnu.org (full text, mbox):
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> On 18.06.2020 09:46, Philip K. wrote:
>
>>> Thank you, I pushed with some minor changes.
>>>
>>> - Docstring further rephrased based on Basil's suggestion.
>>> - The variable renamed to project-kill-buffers-skip-conditions, hope you
>>> don't mind.
>>
>> I don't mind, I just thought that I had sent a patch fixing that
>> already?
>
> If you did, I couldn't find it. Sorry.
My mistake, it seems like I never sent the mail :/ But since it was
mostly the same, it's irrelevant.
>>> Should we add a key binding for it as well?
>>
>> I think 'k' in project-prefix-map would fit well, as soon as that gets
>> merged.
>
> Sounds good.
>
> Unless we also wanted a project-scoped version of kill-buffer?
I'm not sure how interesting that would be. Buf in that case, I think
'k' would be better for that command, and 'K' for kill all the buffers.
--
Philip K.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 15:37:01 GMT)
Full text and
rfc822 format available.
Message #62 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 18.06.2020 17:11, Philip K. wrote:
>>>> Should we add a key binding for it as well?
>>>
>>> I think 'k' in project-prefix-map would fit well, as soon as that gets
>>> merged.
>>
>> Sounds good.
>>
>> Unless we also wanted a project-scoped version of kill-buffer?
>
> I'm not sure how interesting that would be. Buf in that case, I think
> 'k' would be better for that command, and 'K' for kill all the buffers.
Right.
Ok, let's put it on 'k' for now.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 22:37:02 GMT)
Full text and
rfc822 format available.
Message #65 received at 41868 <at> debbugs.gnu.org (full text, mbox):
> On 16.06.2020 20:12, Philip K. wrote:
>> It sounds good, so I used it in the revised patch below, together with a
>> few other minor improvments which Basil mentioned.
>
> Thank you, I pushed with some minor changes.
>
> - Docstring further rephrased based on Basil's suggestion.
Why none of recent changes were mentioned in etc/NEWS?
> - The variable renamed to project-kill-buffers-skip-conditions, hope you
> don't mind.
But we already agreed on a shorter name project-kill-buffers-ignore,
and Philip sent the patch that renames it.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 22:59:02 GMT)
Full text and
rfc822 format available.
Message #68 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 19.06.2020 01:06, Juri Linkov wrote:
> Why none of recent changes were mentioned in etc/NEWS?
Would you like to go ahead and do that?
> 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?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 23:05:02 GMT)
Full text and
rfc822 format available.
Message #71 received at 41868 <at> debbugs.gnu.org (full text, mbox):
>> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 23:11:01 GMT)
Full text and
rfc822 format available.
Message #74 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 19.06.2020 02:02, Juri Linkov wrote:
> 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'?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 23:26:02 GMT)
Full text and
rfc822 format available.
Message #77 received at 41868 <at> debbugs.gnu.org (full text, mbox):
>> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Thu, 18 Jun 2020 23:30:02 GMT)
Full text and
rfc822 format available.
Message #80 received at 41868 <at> debbugs.gnu.org (full text, mbox):
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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Fri, 19 Jun 2020 06:22:02 GMT)
Full text and
rfc822 format available.
Message #83 received at 41868 <at> debbugs.gnu.org (full text, mbox):
> From: Juri Linkov <juri <at> linkov.net>
> Cc: "Philip K." <philip <at> warpmail.net>, Eli Zaretskii <eliz <at> gnu.org>,
> contovob <at> tcd.ie, 41868 <at> debbugs.gnu.org
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Fri, 19 Jun 2020 06:29:01 GMT)
Full text and
rfc822 format available.
Message #86 received at 41868 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Juri Linkov <juri <at> linkov.net> 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.
[0001-Add-project-kill-buffers-command.patch (text/x-diff, inline)]
From 0c84b1097941b983738104b0756fd8db4a7eeac4 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..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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Fri, 26 Jun 2020 00:50:02 GMT)
Full text and
rfc822 format available.
Message #89 received at 41868 <at> debbugs.gnu.org (full text, mbox):
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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Fri, 14 Aug 2020 17:06:01 GMT)
Full text and
rfc822 format available.
Message #92 received at 41868 <at> debbugs.gnu.org (full text, mbox):
"Philip K." <philip <at> warpmail.net> writes:
> +(defcustom project-kill-buffers-ignore
> + '("\\*Help\\*")
(etc)
Looks like this was added some weeks ago, and then renamed? (I fixed up
a missing bit of the rename in maintainer.texi now.) But skimming this
thread, it seems like everything discussed was applied, so I'm closing
this bug report.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Fri, 14 Aug 2020 17:06:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
41868 <at> debbugs.gnu.org and "Philip K." <philip <at> warpmail.net>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Fri, 14 Aug 2020 17:06:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41868
; Package
emacs
.
(Fri, 14 Aug 2020 20:37:02 GMT)
Full text and
rfc822 format available.
Message #99 received at 41868 <at> debbugs.gnu.org (full text, mbox):
On 14.08.2020 20:05, Lars Ingebrigtsen wrote:
> Looks like this was added some weeks ago, and then renamed?
And then renamed again. :-)
> (I fixed up
> a missing bit of the rename in maintainer.texi now.) But skimming this
> thread, it seems like everything discussed was applied, so I'm closing
> this bug report.
Yes, thank you.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 12 Sep 2020 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 219 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.