Function: kill-this-buffer

kill-this-buffer is an interactive and byte-compiled function defined in menu-bar.el.gz.

Signature

(kill-this-buffer)

Documentation

Kill the current buffer.

When called in the minibuffer, get out of the minibuffer using abort-recursive-edit.

This command can be invoked only from a menu or a tool bar. If you want to invoke a similar command with M-x, use kill-current-buffer.

Probably introduced at or before Emacs version 24.3.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/menu-bar.el.gz
(defun kill-this-buffer ()
  "Kill the current buffer.
When called in the minibuffer, get out of the minibuffer
using `abort-recursive-edit'.

This command can be invoked only from a menu or a tool bar.  If you want
to invoke a similar command with `M-x', use `kill-current-buffer'."
  (interactive)
  ;; This colossus of a conditional is necessary to account for the wide
  ;; variety of this command's callers.
  (if (let ((lce last-command-event))
        (eq (cond
             ((atom lce)                ; Selected menu item.
              lce)
             ((mouse-event-p lce)       ; Clicked window tool bar icon.
              ;; Code from window-tool-bar--call-button.
              (let* ((posn (event-start lce))
                     (str (posn-string posn)))
                (get-text-property (cdr str) 'tool-bar-key (car str))))
             (t
              (car lce)))               ; Clicked tool bar icon.
            'kill-buffer))
      (if (let* ((window (or (posn-window (event--posn-at-point))
                             last-event-frame
                            (selected-frame)))
                (frame (if (framep window) window
                         (window-frame window))))
           (not (window-minibuffer-p (frame-selected-window frame))))
         (progn (kill-buffer (current-buffer))
                ;; Also close the current window if
                ;; `menu-bar-close-window' is set.
                (when menu-bar-close-window
                  (ignore-errors (delete-window))))
        (abort-recursive-edit))
    (error "This command must be called from a menu or a tool bar")))