www.delorie.com/gnu/docs/elisp-manual-21/elisp_423.html   search  
 
Buy the book!


GNU Emacs Lisp Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.10 Killing Buffers

Killing a buffer makes its name unknown to Emacs and makes its text space available for other use.

The buffer object for the buffer that has been killed remains in existence as long as anything refers to it, but it is specially marked so that you cannot make it current or display it. Killed buffers retain their identity, however; if you kill two distinct buffers, they remain distinct according to eq although both are dead.

If you kill a buffer that is current or displayed in a window, Emacs automatically selects or displays some other buffer instead. This means that killing a buffer can in general change the current buffer. Therefore, when you kill a buffer, you should also take the precautions associated with changing the current buffer (unless you happen to know that the buffer being killed isn't current). See section 27.2 The Current Buffer.

If you kill a buffer that is the base buffer of one or more indirect buffers, the indirect buffers are automatically killed as well.

The buffer-name of a killed buffer is nil. You can use this feature to test whether a buffer has been killed:

 
(defun buffer-killed-p (buffer)
  "Return t if BUFFER is killed."
  (not (buffer-name buffer)))

Command: kill-buffer buffer-or-name
This function kills the buffer buffer-or-name, freeing all its memory for other uses or to be returned to the operating system. It returns nil.

Any processes that have this buffer as the process-buffer are sent the SIGHUP signal, which normally causes them to terminate. (The basic meaning of SIGHUP is that a dialup line has been disconnected.) See section 37.5 Deleting Processes.

If the buffer is visiting a file and contains unsaved changes, kill-buffer asks the user to confirm before the buffer is killed. It does this even if not called interactively. To prevent the request for confirmation, clear the modified flag before calling kill-buffer. See section 27.5 Buffer Modification.

Killing a buffer that is already dead has no effect.

 
(kill-buffer "foo.unchanged")
     => nil
(kill-buffer "foo.changed")

---------- Buffer: Minibuffer ----------
Buffer foo.changed modified; kill anyway? (yes or no) yes
---------- Buffer: Minibuffer ----------

     => nil

Variable: kill-buffer-query-functions
After confirming unsaved changes, kill-buffer calls the functions in the list kill-buffer-query-functions, in order of appearance, with no arguments. The buffer being killed is the current buffer when they are called. The idea of this feature is that these functions will ask for confirmation from the user. If any of them returns nil, kill-buffer spares the buffer's life.

Variable: kill-buffer-hook
This is a normal hook run by kill-buffer after asking all the questions it is going to ask, just before actually killing the buffer. The buffer to be killed is current when the hook functions run. See section 23.6 Hooks.

Variable: buffer-offer-save
This variable, if non-nil in a particular buffer, tells save-buffers-kill-emacs and save-some-buffers to offer to save that buffer, just as they offer to save file-visiting buffers. The variable buffer-offer-save automatically becomes buffer-local when set for any reason. See section 11.10 Buffer-Local Variables.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003