aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/ChangeLog15
-rw-r--r--src/buffer.c38
-rw-r--r--src/buffer.h10
-rw-r--r--src/data.c11
-rw-r--r--src/dispnew.c8
-rw-r--r--src/fileio.c3
-rw-r--r--src/filelock.c13
-rw-r--r--src/lisp.h3
-rw-r--r--src/minibuf.c23
9 files changed, 60 insertions, 64 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f8f2fa47089..a0a31f0bf3c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,18 @@
12013-08-05 Dmitry Antipov <dmantipov@yandex.ru>
2
3 New macro to iterate over live buffers similar to frames.
4 * buffer.h (FOR_EACH_LIVE_BUFFER): New macro.
5 (Vbuffer_alist, Qpriority, Qbefore_string, Qafter_string):
6 Declare buffer-related variables here to offload lisp.h.
7 * buffer.c (Vbuffer_alist): Adjust comment.
8 (Fget_file_buffer, get_truename_buffer, Fother_buffer)
9 (other_buffer_safely):
10 * data.c (store_symval_forwarding):
11 * dispnew.c (Fframe_or_buffer_changed_p):
12 * fileio.c (Fdo_auto_save):
13 * filelock.c (unlock_all_files):
14 * minibuf.c (read_minibuf): Use FOR_EACH_LIVE_BUFFER.
15
12013-08-04 Paul Eggert <eggert@cs.ucla.edu> 162013-08-04 Paul Eggert <eggert@cs.ucla.edu>
2 17
3 Fix some minor races in hosts lacking mkostemp (Bug#15015). 18 Fix some minor races in hosts lacking mkostemp (Bug#15015).
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))
diff --git a/src/buffer.h b/src/buffer.h
index 641a561cafc..646f8f72232 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1120,9 +1120,19 @@ record_unwind_current_buffer (void)
1120 } \ 1120 } \
1121 } while (0) 1121 } while (0)
1122 1122
1123extern Lisp_Object Vbuffer_alist;
1123extern Lisp_Object Qbefore_change_functions; 1124extern Lisp_Object Qbefore_change_functions;
1124extern Lisp_Object Qafter_change_functions; 1125extern Lisp_Object Qafter_change_functions;
1125extern Lisp_Object Qfirst_change_hook; 1126extern Lisp_Object Qfirst_change_hook;
1127extern Lisp_Object Qpriority, Qbefore_string, Qafter_string;
1128
1129/* FOR_EACH_LIVE_BUFFER (LIST_VAR, BUF_VAR) followed by a statement is
1130 a `for' loop which iterates over the buffers from Vbuffer_alist. */
1131
1132#define FOR_EACH_LIVE_BUFFER(list_var, buf_var) \
1133 for (list_var = Vbuffer_alist; \
1134 (CONSP (list_var) && (buf_var = XCDR (XCAR (list_var)), 1)); \
1135 list_var = XCDR (list_var))
1126 1136
1127/* Get text properties of B. */ 1137/* Get text properties of B. */
1128 1138
diff --git a/src/data.c b/src/data.c
index d1e43ac1b5f..ef3a6965779 100644
--- a/src/data.c
+++ b/src/data.c
@@ -981,19 +981,14 @@ store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newva
981 - (char *) &buffer_defaults); 981 - (char *) &buffer_defaults);
982 int idx = PER_BUFFER_IDX (offset); 982 int idx = PER_BUFFER_IDX (offset);
983 983
984 Lisp_Object tail; 984 Lisp_Object tail, buf;
985 985
986 if (idx <= 0) 986 if (idx <= 0)
987 break; 987 break;
988 988
989 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 989 FOR_EACH_LIVE_BUFFER (tail, buf)
990 { 990 {
991 Lisp_Object lbuf; 991 struct buffer *b = XBUFFER (buf);
992 struct buffer *b;
993
994 lbuf = Fcdr (XCAR (tail));
995 if (!BUFFERP (lbuf)) continue;
996 b = XBUFFER (lbuf);
997 992
998 if (! PER_BUFFER_VALUE_P (b, idx)) 993 if (! PER_BUFFER_VALUE_P (b, idx))
999 set_per_buffer_value (b, offset, newval); 994 set_per_buffer_value (b, offset, newval);
diff --git a/src/dispnew.c b/src/dispnew.c
index c69f4b3bed5..2708252aa8a 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5895,9 +5895,8 @@ pass nil for VARIABLE. */)
5895 goto changed; 5895 goto changed;
5896 } 5896 }
5897 /* Check that the buffer info matches. */ 5897 /* Check that the buffer info matches. */
5898 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5898 FOR_EACH_LIVE_BUFFER (tail, buf)
5899 { 5899 {
5900 buf = XCDR (XCAR (tail));
5901 /* Ignore buffers that aren't included in buffer lists. */ 5900 /* Ignore buffers that aren't included in buffer lists. */
5902 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ') 5901 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
5903 continue; 5902 continue;
@@ -5927,7 +5926,7 @@ pass nil for VARIABLE. */)
5927 n = 1; 5926 n = 1;
5928 FOR_EACH_FRAME (tail, frame) 5927 FOR_EACH_FRAME (tail, frame)
5929 n += 2; 5928 n += 2;
5930 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5929 FOR_EACH_LIVE_BUFFER (tail, buf)
5931 n += 3; 5930 n += 3;
5932 /* Reallocate the vector if data has grown to need it, 5931 /* Reallocate the vector if data has grown to need it,
5933 or if it has shrunk a lot. */ 5932 or if it has shrunk a lot. */
@@ -5952,9 +5951,8 @@ pass nil for VARIABLE. */)
5952 ASET (state, idx, XFRAME (frame)->name); 5951 ASET (state, idx, XFRAME (frame)->name);
5953 idx++; 5952 idx++;
5954 } 5953 }
5955 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5954 FOR_EACH_LIVE_BUFFER (tail, buf)
5956 { 5955 {
5957 buf = XCDR (XCAR (tail));
5958 /* Ignore buffers that aren't included in buffer lists. */ 5956 /* Ignore buffers that aren't included in buffer lists. */
5959 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ') 5957 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
5960 continue; 5958 continue;
diff --git a/src/fileio.c b/src/fileio.c
index 59e84053773..6b24e592bb3 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5618,9 +5618,8 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5618 couldn't handle some ange-ftp'd file. */ 5618 couldn't handle some ange-ftp'd file. */
5619 5619
5620 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++) 5620 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++)
5621 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5621 FOR_EACH_LIVE_BUFFER (tail, buf)
5622 { 5622 {
5623 buf = XCDR (XCAR (tail));
5624 b = XBUFFER (buf); 5623 b = XBUFFER (buf);
5625 5624
5626 /* Record all the buffers that have auto save mode 5625 /* Record all the buffers that have auto save mode
diff --git a/src/filelock.c b/src/filelock.c
index 0f31b7d4deb..cb0bd5c7b96 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -745,16 +745,15 @@ unlock_file (Lisp_Object fn)
745void 745void
746unlock_all_files (void) 746unlock_all_files (void)
747{ 747{
748 register Lisp_Object tail; 748 register Lisp_Object tail, buf;
749 register struct buffer *b; 749 register struct buffer *b;
750 750
751 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 751 FOR_EACH_LIVE_BUFFER (tail, buf)
752 { 752 {
753 b = XBUFFER (XCDR (XCAR (tail))); 753 b = XBUFFER (buf);
754 if (STRINGP (BVAR (b, file_truename)) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) 754 if (STRINGP (BVAR (b, file_truename))
755 { 755 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
756 unlock_file (BVAR (b, file_truename)); 756 unlock_file (BVAR (b, file_truename));
757 }
758 } 757 }
759} 758}
760 759
diff --git a/src/lisp.h b/src/lisp.h
index 5daddb7d335..085acb54348 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -734,6 +734,7 @@ extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p;
734extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil; 734extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil;
735extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qvectorp; 735extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qvectorp;
736extern Lisp_Object Qvector_or_char_table_p, Qwholenump; 736extern Lisp_Object Qvector_or_char_table_p, Qwholenump;
737extern Lisp_Object Qwindow;
737extern Lisp_Object Ffboundp (Lisp_Object); 738extern Lisp_Object Ffboundp (Lisp_Object);
738extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object); 739extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
739 740
@@ -3797,9 +3798,7 @@ extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
3797extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool, 3798extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool,
3798 Lisp_Object, Lisp_Object, Lisp_Object); 3799 Lisp_Object, Lisp_Object, Lisp_Object);
3799extern bool overlay_touches_p (ptrdiff_t); 3800extern bool overlay_touches_p (ptrdiff_t);
3800extern Lisp_Object Vbuffer_alist;
3801extern Lisp_Object other_buffer_safely (Lisp_Object); 3801extern Lisp_Object other_buffer_safely (Lisp_Object);
3802extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
3803extern Lisp_Object get_truename_buffer (Lisp_Object); 3802extern Lisp_Object get_truename_buffer (Lisp_Object);
3804extern void init_buffer_once (void); 3803extern void init_buffer_once (void);
3805extern void init_buffer (void); 3804extern void init_buffer (void);
diff --git a/src/minibuf.c b/src/minibuf.c
index 2c33b83c11b..b3648b8c1ae 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -568,22 +568,15 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
568 bset_directory (current_buffer, ambient_dir); 568 bset_directory (current_buffer, ambient_dir);
569 else 569 else
570 { 570 {
571 Lisp_Object buf_list; 571 Lisp_Object tail, buf;
572 572
573 for (buf_list = Vbuffer_alist; 573 FOR_EACH_LIVE_BUFFER (tail, buf)
574 CONSP (buf_list); 574 if (STRINGP (BVAR (XBUFFER (buf), directory)))
575 buf_list = XCDR (buf_list)) 575 {
576 { 576 bset_directory (current_buffer,
577 Lisp_Object other_buf; 577 BVAR (XBUFFER (buf), directory));
578 578 break;
579 other_buf = XCDR (XCAR (buf_list)); 579 }
580 if (STRINGP (BVAR (XBUFFER (other_buf), directory)))
581 {
582 bset_directory (current_buffer,
583 BVAR (XBUFFER (other_buf), directory));
584 break;
585 }
586 }
587 } 580 }
588 581
589 if (!EQ (mini_frame, selected_frame)) 582 if (!EQ (mini_frame, selected_frame))