From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Philip K." Newsgroups: gmane.emacs.bugs Subject: bug#41868: [PATCH] Add project-clean-up command Date: Tue, 16 Jun 2020 19:12:36 +0200 Message-ID: <877dw7q6ij.fsf@warpmail.net> References: <87k108wsvb.fsf@warpmail.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="71739"; mail-complaints-to="usenet@ciao.gmane.io" Cc: contovob@tcd.ie, 41868@debbugs.gnu.org, dgutov@yandex.ru To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 16 19:28:13 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlFNb-000IZW-HF for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Jun 2020 19:28:12 +0200 Original-Received: from localhost ([::1]:50494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlFNa-0003Ex-IA for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Jun 2020 13:28:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlF8w-00030K-NK for bug-gnu-emacs@gnu.org; Tue, 16 Jun 2020 13:13:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jlF8w-0008JE-E5 for bug-gnu-emacs@gnu.org; Tue, 16 Jun 2020 13:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jlF8w-0006LK-AH for bug-gnu-emacs@gnu.org; Tue, 16 Jun 2020 13:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Philip K." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Jun 2020 17:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41868 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 41868-submit@debbugs.gnu.org id=B41868.159232757124362 (code B ref 41868); Tue, 16 Jun 2020 17:13:02 +0000 Original-Received: (at 41868) by debbugs.gnu.org; 16 Jun 2020 17:12:51 +0000 Original-Received: from localhost ([127.0.0.1]:49522 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jlF8h-0006Kn-2X for submit@debbugs.gnu.org; Tue, 16 Jun 2020 13:12:50 -0400 Original-Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:37021) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jlF8f-0006Kc-R9 for 41868@debbugs.gnu.org; Tue, 16 Jun 2020 13:12:46 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 083D139A; Tue, 16 Jun 2020 13:12:39 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 16 Jun 2020 13:12:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=warpmail.net; h= from:to:cc:subject:in-reply-to:date:message-id:mime-version :content-type; s=fm3; bh=KahKOLXX7PvYqT42QQJs8Vj8H6dWZPVspDzTe0V NyKE=; b=S4rBlGG/P+F02KXizE5oCbEh28Akft0GxYH4axICkOgklrhoxIey3a3 3O7JbsxdhkWVPYqiXIqRMcMFmv5aOhwUIsReS8zw6q0nQL7BgfKsq//VvnBWhYuY 6HDGvuQ3R0bUjf11JoVySpUbXQmcxK04+1vMB9BafCyYhV1vfJs0YPZnTIEEdP1j qaDp3NrP+zUZXuqE02QMdZb0d1yc20vVXI9AQAO7ULo+FnkzsNJEMxT0YVVmKA4D DrnglLR09PeqSUV/V03UU1RN2eY3YtCmfHVIle8rUBKvaV+IKwjJToIx+KZAATcY jG0KcIJqCdH8rapmOt+xh+eJxrTMkHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=KahKOLXX7PvYqT42Q QJs8Vj8H6dWZPVspDzTe0VNyKE=; b=EuXxyx5q2O9iuRwi+P01uckZMALbUIphy 6D+Pvg26X9n7ApIXoXOKzwTXlxKE/IrNFT99I5r/A6BeoHVvVzL8tQMrkaKOhvyL 3xIXq0hHf7r7ZvoHAku+6nCps/ZR8UUesyc9/6Z4bw5HeR90hWvwciIdPb+L54nE HU/Vp+vrHW83FimEJsbSadvRxnlRa5wAbUe9B+6egXpMECIj998QJ/KPmwScaHxN DsQxeSmyH3P5tk+9P6tQOEb2Imjo12sqYTEozOHNn0QeqiljPGpEJJythiSC+GUL /2MIQVqlKUkIVYp80Uj4iyD2mh7+t+SmKa+DhlSoz0xPIVPO55VMw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudejtddguddugecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffujgffkfggtgesmhdtreertddttdenucfhrhhomhepfdfrhhhilhhi phcumfdrfdcuoehphhhilhhiphesfigrrhhpmhgrihhlrdhnvghtqeenucggtffrrghtth gvrhhnpeejieeuvdellefffefgueetkeelkeegveffieeffffhgfeuueehvdelvdeuvefh geenucfkphepjeelrddvudelrdduleelrddvudehnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepphhhihhlihhpseifrghrphhmrghilhdrnhgv th X-ME-Proxy: Original-Received: from localhost (p4fdbc7d7.dip0.t-ipconnect.de [79.219.199.215]) by mail.messagingengine.com (Postfix) with ESMTPA id C0EE4328005D; Tue, 16 Jun 2020 13:12:38 -0400 (EDT) In-Reply-To: <83o8pj13rq.fsf@gnu.org> (message from Eli Zaretskii on Tue, 16 Jun 2020 17:31:05 +0300) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:182032 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: "Basil L. Contovounesios" >> Date: Tue, 16 Jun 2020 11:52:26 +0100 >> Cc: 41868@debbugs.gnu.org, Dmitry Gutov >> >> 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-project-kill-buffers-command.patch >From 2172f4d3d310d75dadf5ef0af297476e873349b8 Mon Sep 17 00:00:00 2001 From: Philip K 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 --=-=-=--