diff options
author | Dmitry Antipov <dmantipov@yandex.ru> | 2013-08-05 08:14:43 +0400 |
---|---|---|
committer | Dmitry Antipov <dmantipov@yandex.ru> | 2013-08-05 08:14:43 +0400 |
commit | 8f3a2c2659ddee1ae84b4b8bb28f6c388f87fd0f (patch) | |
tree | 36980f65ace0a9492e3a28473a89428d6f45c44f /src | |
parent | 3e2cd454fdc04a1afefa23cdfe241c11862eaa8d (diff) | |
download | emacs-8f3a2c2659ddee1ae84b4b8bb28f6c388f87fd0f.tar.gz |
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/ChangeLog | 15 | ||||
-rw-r--r-- | src/buffer.c | 38 | ||||
-rw-r--r-- | src/buffer.h | 10 | ||||
-rw-r--r-- | src/data.c | 11 | ||||
-rw-r--r-- | src/dispnew.c | 8 | ||||
-rw-r--r-- | src/fileio.c | 3 | ||||
-rw-r--r-- | src/filelock.c | 13 | ||||
-rw-r--r-- | src/lisp.h | 3 | ||||
-rw-r--r-- | src/minibuf.c | 23 |
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 @@ +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). 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, 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)) 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) } \ } 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. */ 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 - (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); 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. */) 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; 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. */) 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 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) 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)); } } 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; 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); 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, 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)) |