emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r113695: New macro to iterate over live buffers simi


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r113695: New macro to iterate over live buffers similar to frames.
Date: Mon, 05 Aug 2013 04:15:04 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113695
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Mon 2013-08-05 08:14:43 +0400
message:
  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.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/buffer.c                   buffer.c-20091113204419-o5vbwnq5f7feedwu-264
  src/buffer.h                   buffer.h-20091113204419-o5vbwnq5f7feedwu-196
  src/data.c                     data.c-20091113204419-o5vbwnq5f7feedwu-251
  src/dispnew.c                  dispnew.c-20091113204419-o5vbwnq5f7feedwu-258
  src/fileio.c                   fileio.c-20091113204419-o5vbwnq5f7feedwu-210
  src/filelock.c                 filelock.c-20091113204419-o5vbwnq5f7feedwu-179
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
  src/minibuf.c                  minibuf.c-20091113204419-o5vbwnq5f7feedwu-242
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-08-04 16:56:56 +0000
+++ b/src/ChangeLog     2013-08-05 04:14:43 +0000
@@ -1,3 +1,18 @@
+2013-08-05  Dmitry Antipov  <address@hidden>
+
+       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  <address@hidden>
 
        Fix some minor races in hosts lacking mkostemp (Bug#15015).

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2013-07-16 21:35:45 +0000
+++ b/src/buffer.c      2013-08-05 04:14:43 +0000
@@ -108,9 +108,9 @@
 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 @@
 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 @@
       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 @@
 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 @@
     }
 
   /* 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 @@
 {
   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))

=== modified file 'src/buffer.h'
--- a/src/buffer.h      2013-07-16 21:35:45 +0000
+++ b/src/buffer.h      2013-08-05 04:14:43 +0000
@@ -1120,9 +1120,19 @@
       }                                                                        
\
   } 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.  */
 

=== modified file 'src/data.c'
--- a/src/data.c        2013-08-02 21:16:33 +0000
+++ b/src/data.c        2013-08-05 04:14:43 +0000
@@ -981,19 +981,14 @@
                        - (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);

=== modified file 'src/dispnew.c'
--- a/src/dispnew.c     2013-08-04 04:07:18 +0000
+++ b/src/dispnew.c     2013-08-05 04:14:43 +0000
@@ -5895,9 +5895,8 @@
        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 @@
   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 @@
       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;

=== modified file 'src/fileio.c'
--- a/src/fileio.c      2013-08-01 22:24:02 +0000
+++ b/src/fileio.c      2013-08-05 04:14:43 +0000
@@ -5618,9 +5618,8 @@
      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

=== modified file 'src/filelock.c'
--- a/src/filelock.c    2013-08-04 16:56:56 +0000
+++ b/src/filelock.c    2013-08-05 04:14:43 +0000
@@ -745,16 +745,15 @@
 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));
     }
 }
 

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2013-08-01 22:24:02 +0000
+++ b/src/lisp.h        2013-08-05 04:14:43 +0000
@@ -734,6 +734,7 @@
 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 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);

=== modified file 'src/minibuf.c'
--- a/src/minibuf.c     2013-07-16 21:35:45 +0000
+++ b/src/minibuf.c     2013-08-05 04:14:43 +0000
@@ -568,22 +568,15 @@
     bset_directory (current_buffer, ambient_dir);
   else
     {
-      Lisp_Object buf_list;
-
-      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;
-           }
-       }
+      Lisp_Object tail, buf;
+
+      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))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]