* buffer.h (BUFFER_LIVE_P): New macro.
* alloc.c, buffer.c, editfns.c, insdel.c, lread.c, marker.c:
* minibuf.c, print.c, process.c, window.c, xdisp.c: Use it.
+2012-09-11 Dmitry Antipov <dmantipov@yandex.ru>
+
+ Convenient macro to check whether the buffer is live.
+ * buffer.h (BUFFER_LIVE_P): New macro.
+ * alloc.c, buffer.c, editfns.c, insdel.c, lread.c, marker.c:
+ * minibuf.c, print.c, process.c, window.c, xdisp.c: Use it.
+
2012-09-11 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
* xdisp.c (right_overwritten, right_overwriting): Also handle gstring
struct Lisp_Marker *m;
/* No dead buffers here. */
- eassert (!NILP (BVAR (buf, name)));
+ eassert (BUFFER_LIVE_P (buf));
/* Every character is at least one byte. */
eassert (charpos <= bytepos);
Value is nil if OBJECT is not a buffer or if it has been killed. */)
(Lisp_Object object)
{
- return ((BUFFERP (object) && ! NILP (BVAR (XBUFFER (object), name)))
+ return ((BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))
? Qt : Qnil);
}
base_buffer = Fget_buffer (base_buffer);
if (NILP (base_buffer))
error ("No such buffer: `%s'", SDATA (tem));
- if (NILP (BVAR (XBUFFER (base_buffer), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (base_buffer)))
error ("Base buffer has been killed");
if (SCHARS (name) == 0)
{
buf = XCAR (tail);
if (BUFFERP (buf) && !EQ (buf, buffer)
- && !NILP (BVAR (XBUFFER (buf), name))
+ && BUFFER_LIVE_P (XBUFFER (buf))
&& (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
/* If the frame has a buffer_predicate, disregard buffers that
don't fit the predicate. */
{
buf = Fcdr (XCAR (tail));
if (BUFFERP (buf) && !EQ (buf, buffer)
- && !NILP (BVAR (XBUFFER (buf), name))
+ && BUFFER_LIVE_P (XBUFFER (buf))
&& (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
/* If the frame has a buffer_predicate, disregard buffers that
don't fit the predicate. */
{
buf = Fcdr (XCAR (tail));
if (BUFFERP (buf) && !EQ (buf, buffer)
- && !NILP (BVAR (XBUFFER (buf), name))
+ && BUFFER_LIVE_P (XBUFFER (buf))
&& (SREF (BVAR (XBUFFER (buf), name), 0) != ' '))
return buf;
}
b = XBUFFER (buffer);
/* Avoid trouble for buffer already dead. */
- if (NILP (BVAR (b, name)))
+ if (!BUFFER_LIVE_P (b))
return Qnil;
/* Query if the buffer is still modified. */
}
/* If the hooks have killed the buffer, exit now. */
- if (NILP (BVAR (b, name)))
+ if (!BUFFER_LIVE_P (b))
return Qt;
/* We have no more questions to ask. Verify that it is valid
UNGCPRO;
/* Exit if we now have killed the base buffer (Bug#11665). */
- if (NILP (BVAR (b, name)))
+ if (!BUFFER_LIVE_P (b))
return Qt;
}
replace_buffer_in_windows (buffer);
/* Exit if replacing the buffer in windows has killed our buffer. */
- if (NILP (BVAR (b, name)))
+ if (!BUFFER_LIVE_P (b))
return Qt;
/* Make this buffer not be current. Exit if it is the sole visible
/* Killing buffer processes may run sentinels which may have killed
our buffer. */
- if (NILP (BVAR (b, name)))
+ if (!BUFFER_LIVE_P (b))
return Qt;
/* These may run Lisp code and into infinite loops (if someone
}
/* Deleting an auto-save file could have killed our buffer. */
- if (NILP (BVAR (b, name)))
+ if (!BUFFER_LIVE_P (b))
return Qt;
if (b->base_buffer)
CHECK_BUFFER (buffer);
- if (NILP (BVAR (XBUFFER (buffer), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (buffer)))
error ("Attempt to set major mode for a dead buffer");
if (strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0)
buffer = Fget_buffer (buffer_or_name);
if (NILP (buffer))
nsberror (buffer_or_name);
- if (NILP (BVAR (XBUFFER (buffer), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (buffer)))
error ("Selecting deleted buffer");
set_buffer_internal (XBUFFER (buffer));
return buffer;
Lisp_Object
set_buffer_if_live (Lisp_Object buffer)
{
- if (! NILP (BVAR (XBUFFER (buffer), name)))
+ if (BUFFER_LIVE_P (XBUFFER (buffer)))
set_buffer_internal (XBUFFER (buffer));
return Qnil;
}
CHECK_BUFFER (buffer);
other_buffer = XBUFFER (buffer);
- if (NILP (BVAR (other_buffer, name)))
+ if (!BUFFER_LIVE_P (other_buffer))
error ("Cannot swap a dead buffer's text");
/* Actually, it probably works just fine.
/* Copy this buffer's new multibyte status
into all of its indirect buffers. */
FOR_EACH_BUFFER (other)
- if (other->base_buffer == current_buffer && !NILP (BVAR (other, name)))
+ if (other->base_buffer == current_buffer && BUFFER_LIVE_P (other))
{
BVAR (other, enable_multibyte_characters)
= BVAR (current_buffer, enable_multibyte_characters);
b->INTERNAL_FIELD (width_table) = val;
}
-\f
+/* Convenient check whether buffer B is live. */
+
+#define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name)))
+
/* Chain of all buffers, including killed ones. */
extern struct buffer *all_buffers;
if (NILP (buf))
nsberror (buffer);
bp = XBUFFER (buf);
- if (NILP (BVAR (bp, name)))
+ if (!BUFFER_LIVE_P (bp))
error ("Selecting deleted buffer");
if (NILP (start))
if (NILP (buf1))
nsberror (buffer1);
bp1 = XBUFFER (buf1);
- if (NILP (BVAR (bp1, name)))
+ if (!BUFFER_LIVE_P (bp1))
error ("Selecting deleted buffer");
}
if (NILP (buf2))
nsberror (buffer2);
bp2 = XBUFFER (buf2);
- if (NILP (BVAR (bp2, name)))
+ if (!BUFFER_LIVE_P (bp2))
error ("Selecting deleted buffer");
}
non-nil, and insertion calls a file handler (e.g. through
lock_file) which scribbles into a temp file -- cyd */
if (!BUFFERP (combine_after_change_buffer)
- || NILP (BVAR (XBUFFER (combine_after_change_buffer), name)))
+ || !BUFFER_LIVE_P (XBUFFER (combine_after_change_buffer)))
{
combine_after_change_list = Qnil;
return Qnil;
{
ptrdiff_t count1 = SPECPDL_INDEX ();
- if (b != 0 && NILP (BVAR (b, name)))
+ if (b != 0 && !BUFFER_LIVE_P (b))
error ("Reading from killed buffer");
if (!NILP (start))
does not preserve the buffer from being GC'd (it's weak), so
markers have to be unlinked from their buffer as soon as the buffer
is killed. */
- eassert (!NILP (BVAR (XBUFFER (buf), name)));
+ eassert (BUFFER_LIVE_P (XBUFFER (buf)));
return buf;
}
return Qnil;
if (NILP (buffer))
{
b = current_buffer;
- eassert (!NILP (BVAR (b, name)));
+ eassert (BUFFER_LIVE_P (b));
}
else
{
CHECK_BUFFER (buffer);
b = XBUFFER (buffer);
- if (NILP (BVAR (b, name)))
+ if (!BUFFER_LIVE_P (b))
b = NULL;
}
return b;
register struct Lisp_Marker *tail, **prev;
/* No dead buffers here. */
- eassert (!NILP (BVAR (b, name)));
+ eassert (BUFFER_LIVE_P (b));
marker->buffer = NULL;
prev = &BUF_MARKERS (b);
Vminibuffer_list = nconc2 (Vminibuffer_list, tail);
}
buf = Fcar (tail);
- if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name)))
+ if (NILP (buf) || !BUFFER_LIVE_P (XBUFFER (buf)))
{
buf = Fget_buffer_create
(make_formatted_string (name, " *Minibuf-%"pI"d*", depth));
}
else if (BUFFERP (obj))
{
- if (NILP (BVAR (XBUFFER (obj), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (obj)))
strout ("#<killed buffer>", -1, -1, printcharfun);
else if (escapeflag)
{
}
/* If no filter, write into buffer if it isn't dead. */
- else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name)))
+ else if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
{
Lisp_Object old_read_only;
ptrdiff_t old_begv, old_zv;
/* Avoid error if buffer is deleted
(probably that's why the process is dead, too) */
- if (NILP (BVAR (XBUFFER (buffer), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (buffer)))
continue;
Fset_buffer (buffer);
/* Check for a window that has a killed buffer. */
case CHECK_ALL_WINDOWS:
if (! NILP (w->buffer)
- && NILP (BVAR (XBUFFER (w->buffer), name)))
+ && !BUFFER_LIVE_P (XBUFFER (w->buffer)))
emacs_abort ();
break;
XSETWINDOW (window, w);
buffer = Fget_buffer (buffer_or_name);
CHECK_BUFFER (buffer);
- if (NILP (BVAR (XBUFFER (buffer), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (buffer)))
error ("Attempt to display deleted buffer");
tem = w->buffer;
if (STRINGP (object))
object = Fget_buffer (object);
- if (BUFFERP (object) && !NILP (BVAR (XBUFFER (object), name)))
+ if (BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))
{
/* Walk all windows looking for buffer, and force update
of each of those windows. */
saved_windows = XVECTOR (data->saved_windows);
new_current_buffer = data->current_buffer;
- if (NILP (BVAR (XBUFFER (new_current_buffer), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer)))
new_current_buffer = Qnil;
else
{
w = XWINDOW (window);
if (!NILP (w->buffer)
&& !EQ (w->buffer, p->buffer)
- && !NILP (BVAR (XBUFFER (p->buffer), name)))
+ && BUFFER_LIVE_P (XBUFFER (p->buffer)))
/* If a window we restore gets another buffer, record the
window's old buffer. */
call1 (Qrecord_window_buffer, window);
if (NILP (p->buffer))
/* An internal window. */
wset_buffer (w, p->buffer);
- else if (!NILP (BVAR (XBUFFER (p->buffer), name)))
+ else if (BUFFER_LIVE_P (XBUFFER (p->buffer)))
/* If saved buffer is alive, install it. */
{
wset_buffer (w, p->buffer);
Fgoto_char (w->pointm);
}
else if (!NILP (w->buffer)
- && !NILP (BVAR (XBUFFER (w->buffer), name)))
+ && BUFFER_LIVE_P (XBUFFER (w->buffer)))
/* Keep window's old buffer; make sure the markers are
real. */
{
}
/* There isn't much we can reasonably do to protect against
misbehaving fontification, but here's a fig leaf. */
- else if (!NILP (BVAR (obuf, name)))
+ else if (BUFFER_LIVE_P (obuf))
set_buffer_internal_1 (obuf);
/* The fontification code may have added/removed text.
for (i = 0; i < 2; ++i)
if (!BUFFERP (echo_buffer[i])
- || NILP (BVAR (XBUFFER (echo_buffer[i]), name)))
+ || !BUFFER_LIVE_P (XBUFFER (echo_buffer[i])))
{
char name[30];
Lisp_Object old_buffer;