diff options
| author | Dmitry Antipov | 2012-12-07 11:16:32 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-12-07 11:16:32 +0400 |
| commit | ed08365b9e2756208b0cd2724715b47df6bf5320 (patch) | |
| tree | 234b22e6b305f5ac90b4563a4026fa5a528da626 /src | |
| parent | 8e0762cade0431a3586c9f60234a63df4117a16a (diff) | |
| download | emacs-ed08365b9e2756208b0cd2724715b47df6bf5320.tar.gz emacs-ed08365b9e2756208b0cd2724715b47df6bf5320.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/buffer.c | 25 | ||||
| -rw-r--r-- | src/buffer.h | 5 | ||||
| -rw-r--r-- | 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 @@ | |||
| 1 | 2012-12-07 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Convenient macro to check whether the buffer is hidden. | ||
| 4 | * buffer.h (BUFFER_HIDDEN_P): New macro. | ||
| 5 | * frame.c (make_frame): Use it. Adjust comment. | ||
| 6 | * buffer.c (candidate_buffer): New function. | ||
| 7 | (Fother_buffer, other_buffer_safely): Use it. | ||
| 8 | |||
| 1 | 2012-12-06 Eli Zaretskii <eliz@gnu.org> | 9 | 2012-12-06 Eli Zaretskii <eliz@gnu.org> |
| 2 | 10 | ||
| 3 | * w32proc.c (waitpid): Avoid busy-waiting when called with WNOHANG | 11 | * 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). */) | |||
| 1529 | return BVAR (current_buffer, name); | 1529 | return BVAR (current_buffer, name); |
| 1530 | } | 1530 | } |
| 1531 | 1531 | ||
| 1532 | /* True if B can be used as 'other-than-BUFFER' buffer. */ | ||
| 1533 | |||
| 1534 | static bool | ||
| 1535 | candidate_buffer (Lisp_Object b, Lisp_Object buffer) | ||
| 1536 | { | ||
| 1537 | return (BUFFERP (b) && !EQ (b, buffer) | ||
| 1538 | && BUFFER_LIVE_P (XBUFFER (b)) | ||
| 1539 | && !BUFFER_HIDDEN_P (XBUFFER (b))); | ||
| 1540 | } | ||
| 1541 | |||
| 1532 | DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0, | 1542 | DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0, |
| 1533 | doc: /* Return most recently selected buffer other than BUFFER. | 1543 | doc: /* Return most recently selected buffer other than BUFFER. |
| 1534 | Buffers not visible in windows are preferred to visible buffers, unless | 1544 | Buffers not visible in windows are preferred to visible buffers, unless |
| @@ -1550,9 +1560,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */) | |||
| 1550 | for (; CONSP (tail); tail = XCDR (tail)) | 1560 | for (; CONSP (tail); tail = XCDR (tail)) |
| 1551 | { | 1561 | { |
| 1552 | buf = XCAR (tail); | 1562 | buf = XCAR (tail); |
| 1553 | if (BUFFERP (buf) && !EQ (buf, buffer) | 1563 | if (candidate_buffer (buf, buffer) |
| 1554 | && BUFFER_LIVE_P (XBUFFER (buf)) | ||
| 1555 | && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') | ||
| 1556 | /* If the frame has a buffer_predicate, disregard buffers that | 1564 | /* If the frame has a buffer_predicate, disregard buffers that |
| 1557 | don't fit the predicate. */ | 1565 | don't fit the predicate. */ |
| 1558 | && (NILP (pred) || !NILP (call1 (pred, buf)))) | 1566 | && (NILP (pred) || !NILP (call1 (pred, buf)))) |
| @@ -1570,9 +1578,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */) | |||
| 1570 | for (; CONSP (tail); tail = XCDR (tail)) | 1578 | for (; CONSP (tail); tail = XCDR (tail)) |
| 1571 | { | 1579 | { |
| 1572 | buf = Fcdr (XCAR (tail)); | 1580 | buf = Fcdr (XCAR (tail)); |
| 1573 | if (BUFFERP (buf) && !EQ (buf, buffer) | 1581 | if (candidate_buffer (buf, buffer) |
| 1574 | && BUFFER_LIVE_P (XBUFFER (buf)) | ||
| 1575 | && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') | ||
| 1576 | /* If the frame has a buffer_predicate, disregard buffers that | 1582 | /* If the frame has a buffer_predicate, disregard buffers that |
| 1577 | don't fit the predicate. */ | 1583 | don't fit the predicate. */ |
| 1578 | && (NILP (pred) || !NILP (call1 (pred, buf)))) | 1584 | && (NILP (pred) || !NILP (call1 (pred, buf)))) |
| @@ -1608,13 +1614,10 @@ other_buffer_safely (Lisp_Object buffer) | |||
| 1608 | { | 1614 | { |
| 1609 | Lisp_Object tail, buf; | 1615 | Lisp_Object tail, buf; |
| 1610 | 1616 | ||
| 1611 | tail = Vbuffer_alist; | 1617 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) |
| 1612 | for (; CONSP (tail); tail = XCDR (tail)) | ||
| 1613 | { | 1618 | { |
| 1614 | buf = Fcdr (XCAR (tail)); | 1619 | buf = Fcdr (XCAR (tail)); |
| 1615 | if (BUFFERP (buf) && !EQ (buf, buffer) | 1620 | if (candidate_buffer (buf, buffer)) |
| 1616 | && BUFFER_LIVE_P (XBUFFER (buf)) | ||
| 1617 | && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')) | ||
| 1618 | return buf; | 1621 | return buf; |
| 1619 | } | 1622 | } |
| 1620 | 1623 | ||
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) | |||
| 982 | 982 | ||
| 983 | #define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name))) | 983 | #define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name))) |
| 984 | 984 | ||
| 985 | /* Convenient check whether buffer B is hidden (i.e. its name | ||
| 986 | starts with a space). Caller must ensure that B is live. */ | ||
| 987 | |||
| 988 | #define BUFFER_HIDDEN_P(b) (SREF (BVAR (b, name), 0) == ' ') | ||
| 989 | |||
| 985 | /* Verify indirection counters. */ | 990 | /* Verify indirection counters. */ |
| 986 | 991 | ||
| 987 | #define BUFFER_CHECK_INDIRECTION(b) \ | 992 | #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) | |||
| 346 | 346 | ||
| 347 | /* Choose a buffer for the frame's root window. */ | 347 | /* Choose a buffer for the frame's root window. */ |
| 348 | { | 348 | { |
| 349 | Lisp_Object buf; | 349 | Lisp_Object buf = Fcurrent_buffer (); |
| 350 | 350 | ||
| 351 | wset_buffer (XWINDOW (root_window), Qt); | 351 | wset_buffer (XWINDOW (root_window), Qt); |
| 352 | buf = Fcurrent_buffer (); | 352 | /* If current buffer is hidden, try to find another one. */ |
| 353 | /* If buf is a 'hidden' buffer (i.e. one whose name starts with | 353 | if (BUFFER_HIDDEN_P (XBUFFER (buf))) |
| 354 | a space), try to find another one. */ | ||
| 355 | if (SREF (Fbuffer_name (buf), 0) == ' ') | ||
| 356 | buf = other_buffer_safely (buf); | 354 | buf = other_buffer_safely (buf); |
| 357 | 355 | ||
| 358 | /* Use set_window_buffer, not Fset_window_buffer, and don't let | 356 | /* Use set_window_buffer, not Fset_window_buffer, and don't let |