aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorDmitry Antipov2013-08-05 08:14:43 +0400
committerDmitry Antipov2013-08-05 08:14:43 +0400
commit8f3a2c2659ddee1ae84b4b8bb28f6c388f87fd0f (patch)
tree36980f65ace0a9492e3a28473a89428d6f45c44f /src/buffer.c
parent3e2cd454fdc04a1afefa23cdfe241c11862eaa8d (diff)
downloademacs-8f3a2c2659ddee1ae84b4b8bb28f6c388f87fd0f.tar.gz
emacs-8f3a2c2659ddee1ae84b4b8bb28f6c388f87fd0f.zip
New macro to iterate over live buffers similar to frames.
* buffer.h (FOR_EACH_LIVE_BUFFER): New macro. (Vbuffer_alist, Qpriority, Qbefore_string, Qafter_string): Declare buffer-related variables here to offload lisp.h. * buffer.c (Vbuffer_alist): Adjust comment. (Fget_file_buffer, get_truename_buffer, Fother_buffer) (other_buffer_safely): * data.c (store_symval_forwarding): * dispnew.c (Fframe_or_buffer_changed_p): * fileio.c (Fdo_auto_save): * filelock.c (unlock_all_files): * minibuf.c (read_minibuf): Use FOR_EACH_LIVE_BUFFER.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/buffer.c b/src/buffer.c
index dfc6b8bcc02..f9154d42b03 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -108,9 +108,9 @@ static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
108static void swap_out_buffer_local_variables (struct buffer *b); 108static void swap_out_buffer_local_variables (struct buffer *b);
109static void reset_buffer_local_variables (struct buffer *, bool); 109static void reset_buffer_local_variables (struct buffer *, bool);
110 110
111/* Alist of all buffer names vs the buffers. */ 111/* Alist of all buffer names vs the buffers. This used to be
112/* This used to be a variable, but is no longer, 112 a Lisp-visible variable, but is no longer, to prevent lossage
113 to prevent lossage due to user rplac'ing this alist or its elements. */ 113 due to user rplac'ing this alist or its elements. */
114Lisp_Object Vbuffer_alist; 114Lisp_Object Vbuffer_alist;
115 115
116static Lisp_Object Qkill_buffer_query_functions; 116static Lisp_Object Qkill_buffer_query_functions;
@@ -478,8 +478,7 @@ If there is no such live buffer, return nil.
478See also `find-buffer-visiting'. */) 478See also `find-buffer-visiting'. */)
479 (register Lisp_Object filename) 479 (register Lisp_Object filename)
480{ 480{
481 register Lisp_Object tail, buf, tem; 481 register Lisp_Object tail, buf, handler;
482 Lisp_Object handler;
483 482
484 CHECK_STRING (filename); 483 CHECK_STRING (filename);
485 filename = Fexpand_file_name (filename, Qnil); 484 filename = Fexpand_file_name (filename, Qnil);
@@ -494,13 +493,10 @@ See also `find-buffer-visiting'. */)
494 return BUFFERP (handled_buf) ? handled_buf : Qnil; 493 return BUFFERP (handled_buf) ? handled_buf : Qnil;
495 } 494 }
496 495
497 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 496 FOR_EACH_LIVE_BUFFER (tail, buf)
498 { 497 {
499 buf = Fcdr (XCAR (tail));
500 if (!BUFFERP (buf)) continue;
501 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue; 498 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue;
502 tem = Fstring_equal (BVAR (XBUFFER (buf), filename), filename); 499 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), filename), filename)))
503 if (!NILP (tem))
504 return buf; 500 return buf;
505 } 501 }
506 return Qnil; 502 return Qnil;
@@ -509,15 +505,12 @@ See also `find-buffer-visiting'. */)
509Lisp_Object 505Lisp_Object
510get_truename_buffer (register Lisp_Object filename) 506get_truename_buffer (register Lisp_Object filename)
511{ 507{
512 register Lisp_Object tail, buf, tem; 508 register Lisp_Object tail, buf;
513 509
514 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 510 FOR_EACH_LIVE_BUFFER (tail, buf)
515 { 511 {
516 buf = Fcdr (XCAR (tail));
517 if (!BUFFERP (buf)) continue;
518 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue; 512 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue;
519 tem = Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename); 513 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename)))
520 if (!NILP (tem))
521 return buf; 514 return buf;
522 } 515 }
523 return Qnil; 516 return Qnil;
@@ -1581,10 +1574,8 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1581 } 1574 }
1582 1575
1583 /* Consider alist of all buffers next. */ 1576 /* Consider alist of all buffers next. */
1584 tail = Vbuffer_alist; 1577 FOR_EACH_LIVE_BUFFER (tail, buf)
1585 for (; CONSP (tail); tail = XCDR (tail))
1586 { 1578 {
1587 buf = Fcdr (XCAR (tail));
1588 if (candidate_buffer (buf, buffer) 1579 if (candidate_buffer (buf, buffer)
1589 /* If the frame has a buffer_predicate, disregard buffers that 1580 /* If the frame has a buffer_predicate, disregard buffers that
1590 don't fit the predicate. */ 1581 don't fit the predicate. */
@@ -1621,12 +1612,9 @@ other_buffer_safely (Lisp_Object buffer)
1621{ 1612{
1622 Lisp_Object tail, buf; 1613 Lisp_Object tail, buf;
1623 1614
1624 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 1615 FOR_EACH_LIVE_BUFFER (tail, buf)
1625 { 1616 if (candidate_buffer (buf, buffer))
1626 buf = Fcdr (XCAR (tail)); 1617 return buf;
1627 if (candidate_buffer (buf, buffer))
1628 return buf;
1629 }
1630 1618
1631 buf = Fget_buffer (build_string ("*scratch*")); 1619 buf = Fget_buffer (build_string ("*scratch*"));
1632 if (NILP (buf)) 1620 if (NILP (buf))