Convenient macro to check whether the buffer is hidden.

* buffer.h (BUFFER_HIDDEN_P): New macro.
* frame.c (make_frame): Use it.  Adjust comment.
* buffer.c (candidate_buffer): New function.
(Fother_buffer, other_buffer_safely): Use it.
This commit is contained in:
Dmitry Antipov 2012-12-07 11:16:32 +04:00
parent 8e0762cade
commit ed08365b9e
4 changed files with 30 additions and 16 deletions

View file

@ -1,3 +1,11 @@
2012-12-07 Dmitry Antipov <dmantipov@yandex.ru>
Convenient macro to check whether the buffer is hidden.
* buffer.h (BUFFER_HIDDEN_P): New macro.
* frame.c (make_frame): Use it. Adjust comment.
* buffer.c (candidate_buffer): New function.
(Fother_buffer, other_buffer_safely): Use it.
2012-12-06 Eli Zaretskii <eliz@gnu.org>
* w32proc.c (waitpid): Avoid busy-waiting when called with WNOHANG

View file

@ -1529,6 +1529,16 @@ This does not change the name of the visited file (if any). */)
return BVAR (current_buffer, name);
}
/* True if B can be used as 'other-than-BUFFER' buffer. */
static bool
candidate_buffer (Lisp_Object b, Lisp_Object buffer)
{
return (BUFFERP (b) && !EQ (b, buffer)
&& BUFFER_LIVE_P (XBUFFER (b))
&& !BUFFER_HIDDEN_P (XBUFFER (b)));
}
DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0,
doc: /* Return most recently selected buffer other than BUFFER.
Buffers not visible in windows are preferred to visible buffers, unless
@ -1550,9 +1560,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
for (; CONSP (tail); tail = XCDR (tail))
{
buf = XCAR (tail);
if (BUFFERP (buf) && !EQ (buf, buffer)
&& BUFFER_LIVE_P (XBUFFER (buf))
&& (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
if (candidate_buffer (buf, buffer)
/* If the frame has a buffer_predicate, disregard buffers that
don't fit the predicate. */
&& (NILP (pred) || !NILP (call1 (pred, buf))))
@ -1570,9 +1578,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
for (; CONSP (tail); tail = XCDR (tail))
{
buf = Fcdr (XCAR (tail));
if (BUFFERP (buf) && !EQ (buf, buffer)
&& BUFFER_LIVE_P (XBUFFER (buf))
&& (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
if (candidate_buffer (buf, buffer)
/* If the frame has a buffer_predicate, disregard buffers that
don't fit the predicate. */
&& (NILP (pred) || !NILP (call1 (pred, buf))))
@ -1608,13 +1614,10 @@ other_buffer_safely (Lisp_Object buffer)
{
Lisp_Object tail, buf;
tail = Vbuffer_alist;
for (; CONSP (tail); tail = XCDR (tail))
for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
{
buf = Fcdr (XCAR (tail));
if (BUFFERP (buf) && !EQ (buf, buffer)
&& BUFFER_LIVE_P (XBUFFER (buf))
&& (SREF (BVAR (XBUFFER (buf), name), 0) != ' '))
if (candidate_buffer (buf, buffer))
return buf;
}

View file

@ -982,6 +982,11 @@ bset_width_table (struct buffer *b, Lisp_Object val)
#define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name)))
/* Convenient check whether buffer B is hidden (i.e. its name
starts with a space). Caller must ensure that B is live. */
#define BUFFER_HIDDEN_P(b) (SREF (BVAR (b, name), 0) == ' ')
/* Verify indirection counters. */
#define BUFFER_CHECK_INDIRECTION(b) \

View file

@ -346,13 +346,11 @@ make_frame (int mini_p)
/* Choose a buffer for the frame's root window. */
{
Lisp_Object buf;
Lisp_Object buf = Fcurrent_buffer ();
wset_buffer (XWINDOW (root_window), Qt);
buf = Fcurrent_buffer ();
/* If buf is a 'hidden' buffer (i.e. one whose name starts with
a space), try to find another one. */
if (SREF (Fbuffer_name (buf), 0) == ' ')
/* If current buffer is hidden, try to find another one. */
if (BUFFER_HIDDEN_P (XBUFFER (buf)))
buf = other_buffer_safely (buf);
/* Use set_window_buffer, not Fset_window_buffer, and don't let