[comp.emacs] Problem with buffer object life in GNU Emacs Lisp

weiner@novavax.UUCP (Bob Weiner) (08/05/89)

If you do something like:

(setq rmail-summary-buffer (get-buffer "RMAIL-summary"))

and then kill the actual summary buffer, rmail-summary-buffer will now
reference a 'killed buffer' object.  Typical code uses get-buffer to
check if such a buffer exists, if it does not, get-buffer usually returns
nil.  The global reference rmail-summary-buffer prevents the object from
being garbage collected so (get-buffer "RMAIL-summary") still returns a
non-nil value and your conditional code fails.  But if you try to do
anything with typical operations on this killed buffer you get errors,
as you would expect.

If one made rmail-summary-buffer reference the buffer name instead of
the buffer object, there would be no problem, but often referencing the
object is preferred.

Is there a function such as 'get-non-killed-buffer' which solves this
problem or something else that I am missing?

This is all based on GNU Emacs 18.52.  Thanks for any help.
-- 
Bob Weiner, Motorola, Inc.,   USENET:  ...!gatech!uflorida!novavax!weiner
(407) 738-2087
-- 
Bob Weiner, Motorola, Inc.,   USENET:  ...!gatech!uflorida!novavax!weiner
(407) 738-2087

kjones@talos.uucp (Kyle Jones) (08/07/89)

Bob Weiner writes:
 > If you do something like:
 > 
 > (setq rmail-summary-buffer (get-buffer "RMAIL-summary"))
 > 
 > and then kill the actual summary buffer, rmail-summary-buffer will now
 > reference a 'killed buffer' object.  Typical code uses get-buffer to
 > check if such a buffer exists, if it does not, get-buffer usually returns
 > nil.  The global reference rmail-summary-buffer prevents the object from
 > being garbage collected so (get-buffer "RMAIL-summary") still returns a
 > non-nil value and your conditional code fails.
 > [...]
 > This is all based on GNU Emacs 18.52.  Thanks for any help.

I tried this under GNU Emacs 18.52 here and get-buffer returned nil.
Could you have confused get-buffer with bufferp?  The latter will return
non-nil even if it's argument is a killed buffer.

weiner@novavax.UUCP (Bob Weiner) (08/08/89)

In article <1989Aug7.152011.10962@talos.uucp> kjones@talos.uucp (Kyle Jones) writes:

   Bob Weiner writes:
    > If you do something like:
    > 
    > (setq rmail-summary-buffer (get-buffer "RMAIL-summary"))
    > 
    > and then kill the actual summary buffer, rmail-summary-buffer will now
    > reference a 'killed buffer' object.  Typical code uses get-buffer to
    > check if such a buffer exists, if it does not, get-buffer usually returns
    > nil.  The global reference rmail-summary-buffer prevents the object from
    > being garbage collected so (get-buffer "RMAIL-summary") still returns a
    > non-nil value and your conditional code fails.
    > [...]
    > This is all based on GNU Emacs 18.52.  Thanks for any help.

   I tried this under GNU Emacs 18.52 here and get-buffer returned nil.
   Could you have confused get-buffer with bufferp?  The latter will return
   non-nil even if it's argument is a killed buffer.

For this example, I assumed you had started up RMAIL and had done an {h}
to generate the summary buffer, this automatically performs the setq.
Then you kill the summary buffer and do the get-buffer.  I definitely
have this problem with get-buffer not with bufferp.
-- 
Bob Weiner, Motorola, Inc.,   USENET:  ...!gatech!uflorida!novavax!weiner
(407) 738-2087