Function: project-kill-buffers

project-kill-buffers is an autoloaded, interactive and byte-compiled function defined in project.el.gz.

Signature

(project-kill-buffers &optional NO-CONFIRM PROJECT)

Documentation

Kill the buffers belonging to the current project.

Two buffers belong to the same project if their project instances, as reported by project-current in each buffer, are identical. Only the buffers that match a condition in project-kill-buffer-conditions will be killed. If NO-CONFIRM is non-nil, the command will not ask the user for confirmation. NO-CONFIRM is always nil when the command is invoked interactively.

If PROJECT is non-nil, kill buffers for that project instead.

Also see the project-kill-buffers-display-buffer-list variable.

View in manual

Probably introduced at or before Emacs version 29.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/project.el.gz
;;;###autoload
(defun project-kill-buffers (&optional no-confirm project)
  "Kill the buffers belonging to the current project.
Two buffers belong to the same project if their project
instances, as reported by `project-current' in each buffer, are
identical.  Only the buffers that match a condition in
`project-kill-buffer-conditions' will be killed.  If NO-CONFIRM
is non-nil, the command will not ask the user for confirmation.
NO-CONFIRM is always nil when the command is invoked
interactively.

If PROJECT is non-nil, kill buffers for that project instead.

Also see the `project-kill-buffers-display-buffer-list' variable."
  (interactive)
  (let* ((pr (or project (project-current t)))
         (bufs (project--buffers-to-kill pr))
         (query-user (lambda ()
                       (yes-or-no-p
                        (format "Kill %d buffers in %s? "
                                (length bufs)
                                (project-name pr))))))
    (cond (no-confirm
           (mapc #'kill-buffer bufs))
          ((null bufs)
           (message "No buffers to kill"))
          (project-kill-buffers-display-buffer-list
           (when
               (with-current-buffer-window
                   (get-buffer-create "*Buffer List*")
                   `(display-buffer--maybe-at-bottom
                     (dedicated . t)
                     (window-height . (fit-window-to-buffer))
                     (preserve-size . (nil . t))
                     (body-function
                      . ,#'(lambda (_window)
                             (list-buffers-noselect nil bufs))))
                   #'(lambda (window _value)
                       (with-selected-window window
                         (unwind-protect
                             (funcall query-user)
                           (when (window-live-p window)
                             (quit-restore-window window 'kill))))))
             (mapc #'kill-buffer bufs)))
          ((funcall query-user)
           (mapc #'kill-buffer bufs)))))