From ed08365b9e2756208b0cd2724715b47df6bf5320 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 7 Dec 2012 11:16:32 +0400 Subject: [PATCH] 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. --- src/ChangeLog | 8 ++++++++ src/buffer.c | 25 ++++++++++++++----------- src/buffer.h | 5 +++++ src/frame.c | 8 +++----- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2a138bfcf65..5c92d94ee64 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2012-12-07 Dmitry Antipov + + 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 * w32proc.c (waitpid): Avoid busy-waiting when called with WNOHANG diff --git a/src/buffer.c b/src/buffer.c index 619a729a859..6e2191dc22f 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -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; } diff --git a/src/buffer.h b/src/buffer.h index fbbbf1b8434..1129840bd47 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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) \ diff --git a/src/frame.c b/src/frame.c index ce9ae45eb90..87b21d0a41c 100644 --- a/src/frame.c +++ b/src/frame.c @@ -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 -- 2.39.5