Commit e578f381 authored by Dmitry Antipov's avatar Dmitry Antipov
Browse files

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.
parent 3057e615
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
......
......@@ -3682,7 +3682,7 @@ build_marker (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t bytepos)
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);
......
......@@ -388,7 +388,7 @@ DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0,
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);
}
......@@ -776,7 +776,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
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)
......@@ -1553,7 +1553,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
{
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. */
......@@ -1573,7 +1573,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
{
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. */
......@@ -1615,7 +1615,7 @@ other_buffer_safely (Lisp_Object buffer)
{
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;
}
......@@ -1734,7 +1734,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
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. */
......@@ -1770,7 +1770,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
}
/* 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
......@@ -1802,7 +1802,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
UNGCPRO;
/* Exit if we now have killed the base buffer (Bug#11665). */
if (NILP (BVAR (b, name)))
if (!BUFFER_LIVE_P (b))
return Qt;
}
......@@ -1813,7 +1813,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
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
......@@ -1846,7 +1846,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
/* 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
......@@ -1878,7 +1878,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
}
/* 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)
......@@ -2047,7 +2047,7 @@ the current buffer's major mode. */)
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)
......@@ -2183,7 +2183,7 @@ ends when the current command terminates. Use `switch-to-buffer' or
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;
......@@ -2194,7 +2194,7 @@ ends when the current command terminates. Use `switch-to-buffer' or
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;
}
......@@ -2289,7 +2289,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
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.
......@@ -2685,7 +2685,7 @@ current buffer is cleared. */)
/* 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);
......
......@@ -959,7 +959,10 @@ bset_width_table (struct buffer *b, Lisp_Object val)
b->INTERNAL_FIELD (width_table) = val;
}
/* 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;
......
......@@ -2613,7 +2613,7 @@ They default to the values of (point-min) and (point-max) in BUFFER. */)
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))
......@@ -2677,7 +2677,7 @@ determines whether case is significant or ignored. */)
if (NILP (buf1))
nsberror (buffer1);
bp1 = XBUFFER (buf1);
if (NILP (BVAR (bp1, name)))
if (!BUFFER_LIVE_P (bp1))
error ("Selecting deleted buffer");
}
......@@ -2715,7 +2715,7 @@ determines whether case is significant or ignored. */)
if (NILP (buf2))
nsberror (buffer2);
bp2 = XBUFFER (buf2);
if (NILP (BVAR (bp2, name)))
if (!BUFFER_LIVE_P (bp2))
error ("Selecting deleted buffer");
}
......
......@@ -2107,7 +2107,7 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,
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;
......
......@@ -1734,7 +1734,7 @@ readevalloop (Lisp_Object readcharfun,
{
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))
......
......@@ -407,7 +407,7 @@ Returns nil if MARKER points into a dead buffer. */)
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;
......@@ -462,13 +462,13 @@ live_buffer (Lisp_Object buffer)
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;
......@@ -595,7 +595,7 @@ unchain_marker (register struct Lisp_Marker *marker)
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);
......
......@@ -798,7 +798,7 @@ get_minibuffer (EMACS_INT depth)
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));
......
......@@ -1873,7 +1873,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
}
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)
{
......
......@@ -5298,7 +5298,7 @@ read_process_output (Lisp_Object proc, register int channel)
}
/* 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;
......@@ -6722,7 +6722,7 @@ status_notify (struct Lisp_Process *deleting_process)
/* 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);
......
......@@ -2668,7 +2668,7 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
/* 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;
......@@ -3273,7 +3273,7 @@ This function runs `window-scroll-functions' before running
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;
......@@ -3338,7 +3338,7 @@ displaying that 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. */
......@@ -5549,7 +5549,7 @@ the return value is nil. Otherwise the value is t. */)
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
{
......@@ -5624,7 +5624,7 @@ the return value is nil. Otherwise the value is t. */)
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);
......@@ -5774,7 +5774,7 @@ the return value is nil. Otherwise the value is t. */)
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);
......@@ -5793,7 +5793,7 @@ the return value is nil. Otherwise the value is t. */)
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. */
{
......
......@@ -3667,7 +3667,7 @@ handle_fontified_prop (struct it *it)
}
/* 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.
......@@ -9910,7 +9910,7 @@ ensure_echo_area_buffers (void)
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment