From 4497ef69ed27fff7979966ece8803be1f8918874 Mon Sep 17 00:00:00 2001 From: Philip K 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