]> git.eshelyaron.com Git - emacs.git/commitdiff
New macro to iterate over live buffers similar to frames.
authorDmitry Antipov <dmantipov@yandex.ru>
Mon, 5 Aug 2013 04:14:43 +0000 (08:14 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Mon, 5 Aug 2013 04:14:43 +0000 (08:14 +0400)
* 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.

src/ChangeLog
src/buffer.c
src/buffer.h
src/data.c
src/dispnew.c
src/fileio.c
src/filelock.c
src/lisp.h
src/minibuf.c

index f8f2fa4708973cb811822e349f766f6f3ffc4ca0..a0a31f0bf3c48b05a6251b8da3bb792c5faca3c8 100644 (file)
@@ -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).
index dfc6b8bcc02fe62396d93da27bb0a5d7ef017301..f9154d42b030bab7f663bc47d16086952212579e 100644 (file)
@@ -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))
index 641a561cafc43eb091f316307c6d2a43ad69af84..646f8f72232e9b3848b93d487b33a4b3235df5cd 100644 (file)
@@ -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.  */
 
index d1e43ac1b5fbf00375070d56026ac7d8aed3994c..ef3a6965779dd5c7f4b97198e6bed2cd10fda00a 100644 (file)
@@ -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);
index c69f4b3bed565c04e2208b9a50ac48265e8c90f9..2708252aa8a186cfe2ff03289eefa61baff10434 100644 (file)
@@ -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;
index 59e840537737fde6ffa6410026d4ca069c962cb2..6b24e592bb3085dff50fa49da198a7aba46fe7b6 100644 (file)
@@ -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
index 0f31b7d4deb4cd16b87e7b98bd9ba07394151473..cb0bd5c7b96d19931808cea433a0486229e0af57 100644 (file)
@@ -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));
     }
 }
 \f
index 5daddb7d3350e033de659e6630a03ff7e8cbc1b9..085acb543480837bb8c29817e5b6e55ac41f1f62 100644 (file)
@@ -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);
index 2c33b83c11bdf577eb8c2bbe029f23723fc4e592..b3648b8c1aefa6e0112a61c0ff4a48ddeda88bc4 100644 (file)
@@ -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))