aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip K2020-06-18 04:00:38 +0300
committerDmitry Gutov2020-06-18 04:04:13 +0300
commit7c177ecb8407633e624cd7e12a0c0d12b8990c32 (patch)
tree8458ab52194a839d53454e124f1ed3600e3c1bfc
parent4b9b9cb43a84c1d4c018b9fe1153685e57ffcaa4 (diff)
downloademacs-7c177ecb8407633e624cd7e12a0c0d12b8990c32.tar.gz
emacs-7c177ecb8407633e624cd7e12a0c0d12b8990c32.zip
New command: project-kill-buffers
* lisp/progmodes/project.el (project-kill-buffers-skip-conditions): New variable. (project--buffer-list): New function. (project-kill-buffers): New command (bug#41868).
-rw-r--r--lisp/progmodes/project.el41
1 files changed, 41 insertions, 0 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index e772570b9e1..e24d81c1b43 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -785,6 +785,47 @@ Arguments the same as in `compile'."
785 (when-let ((file (buffer-file-name (cdr buffer)))) 785 (when-let ((file (buffer-file-name (cdr buffer))))
786 (file-in-directory-p file root))))))) 786 (file-in-directory-p file root)))))))
787 787
788(defcustom project-kill-buffers-skip-conditions
789 '("\\*Help\\*")
790 "Conditions for buffers `project-kill-buffers' should not kill.
791Each condition is either a regular expression matching a buffer
792name, or a predicate function that takes a buffer object as
793argument and returns non-nil if it matches. Buffers that match
794any of the conditions will not be killed."
795 :type '(repeat (choice regexp function))
796 :version "28.1")
797
798(defun project--buffer-list (pr)
799 "Return the list of all buffers in project PR."
800 (let ((root (project-root pr))
801 bufs)
802 (dolist (buf (buffer-list))
803 (let ((filename (or (buffer-file-name buf)
804 (buffer-local-value 'default-directory buf))))
805 (when (and filename (file-in-directory-p filename root))
806 (push buf bufs))))
807 (nreverse bufs)))
808
809;;;###autoload
810(defun project-kill-buffers ()
811 "Kill all live buffers belonging to the current project.
812Certain buffers may be ignored, depending on the value of
813`project-kill-buffers-skip-conditions'."
814 (interactive)
815 (let ((pr (project-current t)) bufs)
816 (dolist (buf (project--buffer-list pr))
817 (unless (seq-some
818 (lambda (c)
819 (cond ((stringp c)
820 (string-match-p c (buffer-name buf)))
821 ((functionp c)
822 (funcall c buf))))
823 project-kill-buffers-skip-conditions)
824 (push buf bufs)))
825 (when (yes-or-no-p (format "Kill %d buffers in %s? "
826 (length bufs) (project-root pr)))
827 (mapc #'kill-buffer bufs))))
828
788 829
789;;; Project list 830;;; Project list
790 831