bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#42386: Acknowledgement ([PATCH] Handle symbols in project-kill-buffe


From: Philip K.
Subject: bug#42386: Acknowledgement ([PATCH] Handle symbols in project-kill-buffers-ignores)
Date: Fri, 17 Jul 2020 17:30:52 +0200

The patch below should implement that behaviour + an updating docstring.

Eli Zaretskii <eliz@gnu.org> writes:

>> From: "Philip K." <philip@warpmail.net>
>> Cc: 42386@debbugs.gnu.org
>> Date: Fri, 17 Jul 2020 13:17:17 +0200
>> 
>> > Dmitry suggested a cons cell, which will allow you to differentiate
>> > between predicates and major-modes.  Isn't that a way around the
>> > problem?
>> 
>> That's what I had in mind when I wrote:
>> 
>> > How about this: Instead of symbols, adding a cons-cell:
>> > 
>> >     (major-mode . erc-mode)
>> > 
>> > prevents erc-buffers from being killed?
>> 
>> So if you're ok with that, I'll try submitting a patch with that
>> approach.
>
> Sure, I'm okay.  Especially since Dmitry seems also okay with it.
>
> Thanks.
>

-- 
        Philip K.

>From 4497ef69ed27fff7979966ece8803be1f8918874 Mon Sep 17 00:00:00 2001
From: Philip K <philip@warpmail.net>
Date: Thu, 16 Jul 2020 10:03:35 +0200
Subject: [PATCH] Handle symbols in project-kill-buffers-ignores

---
 lisp/progmodes/project.el | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 67ce3dc7d9..a73ab8ce8a 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -846,11 +846,18 @@ project-switch-to-buffer
 (defcustom project-kill-buffers-ignores
   '("\\*Help\\*")
   "Conditions for buffers `project-kill-buffers' should not kill.
-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.  Buffers that match
-any of the conditions will not be killed."
-  :type '(repeat (choice regexp function))
+Each condition is either:
+- a regular expression, to match a buffer name,
+- a predicate function that takes a buffer object as argument
+  and returns non-nil if the buffer should not be killed,
+- a cons-cell, where the car describes how to interpret the cdr.
+  If the car contains `major-mode', the cdr has to be the symbol
+  of a major mode, that should never be killed.
+
+Buffers that match any of the conditions will not be killed."
+  :type '(repeat (choice regexp function
+                         (cons :tag "Major mode"
+                               (const major-mode) symbol)))
   :version "28.1"
   :package-version '(project . "0.5.0"))
 
@@ -878,12 +885,18 @@ project-kill-buffers
                  (cond ((stringp c)
                         (string-match-p c (buffer-name buf)))
                        ((functionp c)
-                        (funcall c buf))))
+                        (funcall c buf))
+                       ((eq (car-safe c) 'major-mode)
+                        (provided-mode-derived-p
+                         (buffer-local-value 'major-mode buf)
+                         (cdr c)))))
                project-kill-buffers-ignores)
         (push buf bufs)))
-    (when (yes-or-no-p (format "Kill %d buffers in %s? "
-                               (length bufs) (project-root pr)))
-      (mapc #'kill-buffer bufs))))
+    (if (null bufs)
+        (message "No buffers to kill")
+      (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 via email to

[Prev in Thread] Current Thread [Next in Thread]