]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp.h (FOR_EACH_ALIST_VALUE): New macro
authorDmitry Antipov <dmantipov@yandex.ru>
Thu, 15 Aug 2013 14:52:53 +0000 (18:52 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Thu, 15 Aug 2013 14:52:53 +0000 (18:52 +0400)
to do `for' loops over alist values.
* buffer.h (FOR_EACH_BUFFER):
* process.c (FOR_EACH_PROCESS): Use it.
(handle_child_signal, status_notify, Fget_buffer_process)
(kill_buffer_processes): Use FOR_EACH_PROCESS.

src/ChangeLog
src/buffer.h
src/lisp.h
src/process.c

index 0d3982618b7a501e9ae38391bc7cd68213c767c7..1ad3e1cff24657c23561d1e1b53826784825de9c 100644 (file)
@@ -1,3 +1,12 @@
+2013-08-15  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       * lisp.h (FOR_EACH_ALIST_VALUE): New macro
+       to do `for' loops over alist values.
+       * buffer.h (FOR_EACH_BUFFER):
+       * process.c (FOR_EACH_PROCESS): Use it.
+       (handle_child_signal, status_notify, Fget_buffer_process)
+       (kill_buffer_processes): Use FOR_EACH_PROCESS.
+
 2013-08-15  Dmitry Antipov  <dmantipov@yandex.ru>
 
        * term.c (get_named_tty, create_tty_output, tty_free_frame_resources)
index 221db39329aaf4744b45065a268f6b21151ee638..55a9e8d2a1cdf1b131c31c750aefdfd17f8ac4b3 100644 (file)
@@ -1132,10 +1132,8 @@ 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))
+#define FOR_EACH_LIVE_BUFFER(list_var, buf_var)                        \
+  FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var)
 
 /* Get text properties of B.  */
 
index 6d79bb1d6a5f15c656f45e22e0144130a7e85615..e6e90e1e9681221aa8e5b54a77791bc16bced221 100644 (file)
@@ -4342,6 +4342,12 @@ extern void *record_xmalloc (size_t);
       memory_full (SIZE_MAX);                                 \
   } while (0)
 
+/* Do a `for' loop over alist values.  */
+
+#define FOR_EACH_ALIST_VALUE(head_var, list_var, value_var)            \
+  for (list_var = head_var;                                            \
+       (CONSP (list_var) && (value_var = XCDR (XCAR (list_var)), 1));  \
+       list_var = XCDR (list_var))
 
 /* Check whether it's time for GC, and run it if so.  */
 
index c803d69d6d8aab3ff9f2e0c4f018e8bc82ae53b2..892a5aa86c58e2d99a69942cee46b9e672f47cd3 100644 (file)
@@ -361,6 +361,12 @@ static struct sockaddr_and_len {
 #define DATAGRAM_CONN_P(proc)  (0)
 #endif
 
+/* FOR_EACH_PROCESS (LIST_VAR, PROC_VAR) followed by a statement is
+   a `for' loop which iterates over processes from Vprocess_alist.  */
+
+#define FOR_EACH_PROCESS(list_var, proc_var)                   \
+  FOR_EACH_ALIST_VALUE (Vprocess_alist, list_var, proc_var)
+
 /* These setters are used only in this file, so they can be private.  */
 static void
 pset_buffer (struct Lisp_Process *p, Lisp_Object val)
@@ -6135,7 +6141,7 @@ static signal_handler_t volatile lib_child_handler;
 static void
 handle_child_signal (int sig)
 {
-  Lisp_Object tail;
+  Lisp_Object tail, proc;
 
   /* Find the process that signaled us, and record its status.  */
 
@@ -6165,9 +6171,8 @@ handle_child_signal (int sig)
     }
 
   /* Otherwise, if it is asynchronous, it is in Vprocess_alist.  */
-  for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
+  FOR_EACH_PROCESS (tail, proc)
     {
-      Lisp_Object proc = XCDR (XCAR (tail));
       struct Lisp_Process *p = XPROCESS (proc);
       int status;
 
@@ -6322,13 +6327,10 @@ status_notify (struct Lisp_Process *deleting_process)
      that we run, we get called again to handle their status changes.  */
   update_tick = process_tick;
 
-  for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
+  FOR_EACH_PROCESS (tail, proc)
     {
       Lisp_Object symbol;
-      register struct Lisp_Process *p;
-
-      proc = Fcdr (XCAR (tail));
-      p = XPROCESS (proc);
+      register struct Lisp_Process *p = XPROCESS (proc);
 
       if (p->tick != p->update_tick)
        {
@@ -6851,12 +6853,9 @@ BUFFER may be a buffer or the name of one.  */)
   buf = Fget_buffer (buffer);
   if (NILP (buf)) return Qnil;
 
-  for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
-    {
-      proc = Fcdr (XCAR (tail));
-      if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
-       return proc;
-    }
+  FOR_EACH_PROCESS (tail, proc)
+    if (EQ (XPROCESS (proc)->buffer, buf))
+      return proc;
 #endif /* subprocesses */
   return Qnil;
 }
@@ -6889,18 +6888,14 @@ kill_buffer_processes (Lisp_Object buffer)
 #ifdef subprocesses
   Lisp_Object tail, proc;
 
-  for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
-    {
-      proc = XCDR (XCAR (tail));
-      if (PROCESSP (proc)
-         && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)))
-       {
-         if (NETCONN_P (proc) || SERIALCONN_P (proc))
-           Fdelete_process (proc);
-         else if (XPROCESS (proc)->infd >= 0)
-           process_send_signal (proc, SIGHUP, Qnil, 1);
-       }
-    }
+  FOR_EACH_PROCESS (tail, proc)
+    if (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer))
+      {
+       if (NETCONN_P (proc) || SERIALCONN_P (proc))
+         Fdelete_process (proc);
+       else if (XPROCESS (proc)->infd >= 0)
+         process_send_signal (proc, SIGHUP, Qnil, 1);
+      }
 #else  /* subprocesses */
   /* Since we have no subprocesses, this does nothing.  */
 #endif /* subprocesses */