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 00:22:56 +0200

Eli Zaretskii <eliz@gnu.org> writes:

>> How about this: Instead of symbols, adding a cons-cell:
>> 
>>     (major-mode . erc-mode)
>> 
>> prevents erc-buffers from being killed?
>
> You are trying to separate modes from other functions?  Why?  

I figured it would keep the structure simpler, that way it wouldn't be
necessary to distinguish between major modes and predicates. I'd also
see it reducing the ambiguity from the user-side.

> Just see if the major-mode's symbol is in the list, and if so, spare
> the buffer.  Otherwise, if it's a function, call that function
> assuming it's a predicate.  Does this present some problems?

Hmm, it seems to work, but my initial attempt doesn't look that
nice. I'll think about improving it tomorrow, but I'm still more
attracted to the (major-mode . mode-name) approach.

-- 
        Philip K.

>From d7b8357942fcfb33d9b8f3dbef1aefb6849e05d4 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 | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 67ce3dc7d9..7594fe18ac 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -844,13 +844,14 @@ project-switch-to-buffer
       predicate))))
 
 (defcustom project-kill-buffers-ignores
-  '("\\*Help\\*")
+  '(emacs-lisp-mode "\\*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))
+name, a predicate function that takes a buffer object as argument
+and returns non-nil if it matches, or a symbol that prevents
+buffers from being killed, if it equals buffer's major mode.
+Buffers that match any of the conditions will not be killed."
+  :type '(repeat (choice regexp function symbol))
   :version "28.1"
   :package-version '(project . "0.5.0"))
 
@@ -873,17 +874,22 @@ project-kill-buffers
   (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-ignores)
+      (unless (or (memq (buffer-local-value 'major-mode buf)
+                        project-kill-buffers-ignores)
+                  (seq-some
+                   (lambda (c)
+                     (cond ((stringp c)
+                            (string-match-p c (buffer-name buf)))
+                           ((and (not (memq c project-kill-buffers-ignores))
+                                 (functionp c))
+                            (funcall c buf))))
+                   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]