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.
This commit is contained in:
parent
3e2cd454fd
commit
8f3a2c2659
9 changed files with 60 additions and 64 deletions
|
@ -1,3 +1,18 @@
|
|||
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).
|
||||
|
|
38
src/buffer.c
38
src/buffer.c
|
@ -108,9 +108,9 @@ static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
|
|||
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;
|
||||
|
@ -478,8 +478,7 @@ If there is no such live buffer, return nil.
|
|||
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);
|
||||
|
@ -494,13 +493,10 @@ See also `find-buffer-visiting'. */)
|
|||
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;
|
||||
|
@ -509,15 +505,12 @@ See also `find-buffer-visiting'. */)
|
|||
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;
|
||||
|
@ -1581,10 +1574,8 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
|
|||
}
|
||||
|
||||
/* 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. */
|
||||
|
@ -1621,12 +1612,9 @@ other_buffer_safely (Lisp_Object buffer)
|
|||
{
|
||||
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))
|
||||
|
|
10
src/buffer.h
10
src/buffer.h
|
@ -1120,9 +1120,19 @@ record_unwind_current_buffer (void)
|
|||
} \
|
||||
} 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. */
|
||||
|
||||
|
|
11
src/data.c
11
src/data.c
|
@ -981,19 +981,14 @@ store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newva
|
|||
- (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);
|
||||
|
|
|
@ -5895,9 +5895,8 @@ pass nil for VARIABLE. */)
|
|||
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;
|
||||
|
@ -5927,7 +5926,7 @@ pass nil for VARIABLE. */)
|
|||
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. */
|
||||
|
@ -5952,9 +5951,8 @@ pass nil for VARIABLE. */)
|
|||
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;
|
||||
|
|
|
@ -5618,9 +5618,8 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
|
|||
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
|
||||
|
|
|
@ -745,16 +745,15 @@ unlock_file (Lisp_Object fn)
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -734,6 +734,7 @@ extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p;
|
|||
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);
|
||||
|
||||
|
@ -3797,9 +3798,7 @@ extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
|
|||
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);
|
||||
|
|
|
@ -568,22 +568,15 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
|
|||
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))
|
||||
|
|
Loading…
Add table
Reference in a new issue