* 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.
+2013-08-05 Dmitry Antipov <dmantipov@yandex.ru>
+
+ 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.
+
2013-08-04 Paul Eggert <eggert@cs.ucla.edu>
Fix some minor races in hosts lacking mkostemp (Bug#15015).
static void swap_out_buffer_local_variables (struct buffer *b);
static void reset_buffer_local_variables (struct buffer *, bool);
-/* Alist of all buffer names vs the buffers. */
-/* This used to be a variable, but is no longer,
- to prevent lossage due to user rplac'ing this alist or its elements. */
+/* Alist of all buffer names vs the buffers. This used to be
+ a Lisp-visible variable, but is no longer, to prevent lossage
+ due to user rplac'ing this alist or its elements. */
Lisp_Object Vbuffer_alist;
static Lisp_Object Qkill_buffer_query_functions;
See also `find-buffer-visiting'. */)
(register Lisp_Object filename)
{
- register Lisp_Object tail, buf, tem;
- Lisp_Object handler;
+ register Lisp_Object tail, buf, handler;
CHECK_STRING (filename);
filename = Fexpand_file_name (filename, Qnil);
return BUFFERP (handled_buf) ? handled_buf : Qnil;
}
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- buf = Fcdr (XCAR (tail));
- if (!BUFFERP (buf)) continue;
if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue;
- tem = Fstring_equal (BVAR (XBUFFER (buf), filename), filename);
- if (!NILP (tem))
+ if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), filename), filename)))
return buf;
}
return Qnil;
Lisp_Object
get_truename_buffer (register Lisp_Object filename)
{
- register Lisp_Object tail, buf, tem;
+ register Lisp_Object tail, buf;
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- buf = Fcdr (XCAR (tail));
- if (!BUFFERP (buf)) continue;
if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue;
- tem = Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename);
- if (!NILP (tem))
+ if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename)))
return buf;
}
return Qnil;
}
/* Consider alist of all buffers next. */
- tail = Vbuffer_alist;
- for (; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- buf = Fcdr (XCAR (tail));
if (candidate_buffer (buf, buffer)
/* If the frame has a buffer_predicate, disregard buffers that
don't fit the predicate. */
{
Lisp_Object tail, buf;
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
- {
- buf = Fcdr (XCAR (tail));
- if (candidate_buffer (buf, buffer))
- return buf;
- }
+ FOR_EACH_LIVE_BUFFER (tail, buf)
+ if (candidate_buffer (buf, buffer))
+ return buf;
buf = Fget_buffer (build_string ("*scratch*"));
if (NILP (buf))
} \
} while (0)
+extern Lisp_Object Vbuffer_alist;
extern Lisp_Object Qbefore_change_functions;
extern Lisp_Object Qafter_change_functions;
extern Lisp_Object Qfirst_change_hook;
+extern Lisp_Object Qpriority, Qbefore_string, Qafter_string;
+
+/* FOR_EACH_LIVE_BUFFER (LIST_VAR, BUF_VAR) followed by a statement is
+ a `for' loop which iterates over the buffers from Vbuffer_alist. */
+
+#define FOR_EACH_LIVE_BUFFER(list_var, buf_var) \
+ for (list_var = Vbuffer_alist; \
+ (CONSP (list_var) && (buf_var = XCDR (XCAR (list_var)), 1)); \
+ list_var = XCDR (list_var))
/* Get text properties of B. */
- (char *) &buffer_defaults);
int idx = PER_BUFFER_IDX (offset);
- Lisp_Object tail;
+ Lisp_Object tail, buf;
if (idx <= 0)
break;
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- Lisp_Object lbuf;
- struct buffer *b;
-
- lbuf = Fcdr (XCAR (tail));
- if (!BUFFERP (lbuf)) continue;
- b = XBUFFER (lbuf);
+ struct buffer *b = XBUFFER (buf);
if (! PER_BUFFER_VALUE_P (b, idx))
set_per_buffer_value (b, offset, newval);
goto changed;
}
/* Check that the buffer info matches. */
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- buf = XCDR (XCAR (tail));
/* Ignore buffers that aren't included in buffer lists. */
if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
continue;
n = 1;
FOR_EACH_FRAME (tail, frame)
n += 2;
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
n += 3;
/* Reallocate the vector if data has grown to need it,
or if it has shrunk a lot. */
ASET (state, idx, XFRAME (frame)->name);
idx++;
}
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- buf = XCDR (XCAR (tail));
/* Ignore buffers that aren't included in buffer lists. */
if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
continue;
couldn't handle some ange-ftp'd file. */
for (do_handled_files = 0; do_handled_files < 2; do_handled_files++)
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- buf = XCDR (XCAR (tail));
b = XBUFFER (buf);
/* Record all the buffers that have auto save mode
void
unlock_all_files (void)
{
- register Lisp_Object tail;
+ register Lisp_Object tail, buf;
register struct buffer *b;
- for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+ FOR_EACH_LIVE_BUFFER (tail, buf)
{
- b = XBUFFER (XCDR (XCAR (tail)));
- if (STRINGP (BVAR (b, file_truename)) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
- {
- unlock_file (BVAR (b, file_truename));
- }
+ b = XBUFFER (buf);
+ if (STRINGP (BVAR (b, file_truename))
+ && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
+ unlock_file (BVAR (b, file_truename));
}
}
\f
extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil;
extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qvectorp;
extern Lisp_Object Qvector_or_char_table_p, Qwholenump;
+extern Lisp_Object Qwindow;
extern Lisp_Object Ffboundp (Lisp_Object);
extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool,
Lisp_Object, Lisp_Object, Lisp_Object);
extern bool overlay_touches_p (ptrdiff_t);
-extern Lisp_Object Vbuffer_alist;
extern Lisp_Object other_buffer_safely (Lisp_Object);
-extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
extern Lisp_Object get_truename_buffer (Lisp_Object);
extern void init_buffer_once (void);
extern void init_buffer (void);
bset_directory (current_buffer, ambient_dir);
else
{
- Lisp_Object buf_list;
+ Lisp_Object tail, buf;
- for (buf_list = Vbuffer_alist;
- CONSP (buf_list);
- buf_list = XCDR (buf_list))
- {
- Lisp_Object other_buf;
-
- other_buf = XCDR (XCAR (buf_list));
- if (STRINGP (BVAR (XBUFFER (other_buf), directory)))
- {
- bset_directory (current_buffer,
- BVAR (XBUFFER (other_buf), directory));
- break;
- }
- }
+ FOR_EACH_LIVE_BUFFER (tail, buf)
+ if (STRINGP (BVAR (XBUFFER (buf), directory)))
+ {
+ bset_directory (current_buffer,
+ BVAR (XBUFFER (buf), directory));
+ break;
+ }
}
if (!EQ (mini_frame, selected_frame))