(child_setup, getenv_internal): Use the frame's `display'
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 21 Sep 2007 06:58:51 +0000 (06:58 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 21 Sep 2007 06:58:51 +0000 (06:58 +0000)
parameter rather than Qdisplay_environment_variable.  If all else
fails, look for DISPLAY in initial-environment.

src/ChangeLog
src/callproc.c

index 6b6e492..1c303f8 100644 (file)
@@ -1,11 +1,16 @@
+2007-09-21  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * callproc.c (child_setup, getenv_internal): Use the frame's `display'
+       parameter rather than Qdisplay_environment_variable.  If all else
+       fails, look for DISPLAY in initial-environment.
+
 2007-09-21  Glenn Morris  <rgm@gnu.org>
 
        * Makefile.in (emacstool): Remove target.
 
 2007-09-21  Markus Triska  <markus.triska@gmx.at>
 
-       * xterm.c (x_delete_display): Compile session management
-        conditionally.
+       * xterm.c (x_delete_display): Compile session management conditionally.
 
 2007-09-20  Stefan Monnier  <monnier@iro.umontreal.ca>
 
@@ -13,7 +18,7 @@
        (getenv_internal): Use it.
        (Fgetenv_internal): Use it.  Accept an env-list as optional arg.
 
-       * terminal.c (get_terminal): Don't accept integers to represent terminals.
+       * terminal.c (get_terminal): Don't accept ints to represent terminals.
        (Fterminal_name, Fterminal_parameters, Fterminal_parameter)
        (Fset_terminal_parameter): Work with dead terminals as well.
        (Fmodify_terminal_parameters): Remove.
@@ -32,7 +37,8 @@
 
        * alloc.c (enum mem_type): New member for `terminal' objects.
        (allocate_terminal): New function.
-       (mark_maybe_pointer, valid_lisp_object_p, mark_object): Handle terminals.
+       (mark_maybe_pointer, valid_lisp_object_p, mark_object):
+       Handle terminals.
        (mark_terminal): New fun.
        (mark_terminals): Move from terminal.c.
 
index fafbfbf..0fa0c3a 100644 (file)
@@ -141,6 +141,8 @@ int synch_process_retcode;
 /* Nonzero if this is termination due to exit.  */
 static int call_process_exited;
 
+EXFUN (Fgetenv_internal, 2);
+
 #ifndef VMS  /* VMS version is in vmsproc.c.  */
 
 static Lisp_Object
@@ -1326,29 +1328,36 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
     register char **new_env;
     char **p, **q;
     register int new_length;
-    Lisp_Object local = selected_frame; /* get_frame_param (XFRAME (Fframe_with_environment (selected_frame)), */
-/*                                          Qenvironment); */
-
-    Lisp_Object display;
+    Lisp_Object display = Qnil;
     
     new_length = 0;
 
     for (tem = Vprocess_environment;
          CONSP (tem) && STRINGP (XCAR (tem));
          tem = XCDR (tem))
-      new_length++;
-
-#if 0    
-    for (tem = local;
-        CONSP (tem) && STRINGP (XCAR (tem));
-        tem = XCDR (tem))
-      new_length++;
-#endif
+      {
+       if (strncmp (SDATA (XCAR (tem)), "DISPLAY", 7) == 0
+           && (SDATA (XCAR (tem)) [7] == '\0'
+               || SDATA (XCAR (tem)) [7] == '='))
+         /* DISPLAY is specified in process-environment.  */
+         display = Qt;
+       new_length++;
+      }
 
-    /* Add DISPLAY from the frame local values. */
-    display = get_frame_param (XFRAME (local), Qdisplay_environment_variable);
-    if (! NILP (display))
-      new_length++;
+    /* If not provided yet, use the frame's DISPLAY.  */
+    if (NILP (display))
+      {
+       Lisp_Object tmp = Fframe_parameter (selected_frame, Qdisplay);
+       if (!STRINGP (tmp) && CONSP (Vinitial_environment))
+         /* If still not found, Look for DISPLAY in Vinitial_environment.  */
+         tmp = Fgetenv_internal (build_string ("DISPLAY"),
+                                 Vinitial_environment);
+       if (STRINGP (tmp))
+         {
+           display = tmp;
+           new_length++;
+         }
+      }
 
     /* new_length + 2 to include PWD and terminating 0.  */
     env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
@@ -1370,20 +1379,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
     for (tem = Vprocess_environment;
         CONSP (tem) && STRINGP (XCAR (tem));
         tem = XCDR (tem))
-      {
-       if (strcmp (SDATA (XCAR (tem)), "DISPLAY") != 0)
-         new_env = add_env (env, new_env, SDATA (XCAR (tem)));
-      }
-
-  
-#if 0    
-    /* Local part of environment.  */
-    for (tem = local;
-         CONSP (tem) && STRINGP (XCAR (tem));
-         tem = XCDR (tem))
       new_env = add_env (env, new_env, SDATA (XCAR (tem)));
-#endif
-    
+
     *new_env = 0;
 
     /* Remove variable names without values.  */
@@ -1558,44 +1555,28 @@ getenv_internal (var, varlen, value, valuelen, frame)
      int *valuelen;
      Lisp_Object frame;
 {
-  Lisp_Object display;
-
-  /* FIXME: weird behavior.  */
-
-  if (NILP (frame))
-    {
-      /* Try to find VAR in Vprocess_environment first.  */
-      if (getenv_internal_1 (var, varlen, value, valuelen,
-                            Vprocess_environment))
-       return value ? 1 : 0;
-      else
-       frame = selected_frame;
-    }
+  /* Try to find VAR in Vprocess_environment first.  */
+  if (getenv_internal_1 (var, varlen, value, valuelen,
+                        Vprocess_environment))
+    return *value ? 1 : 0;
 
-  /* For DISPLAY first try to get the values from the frame. */
-  display = get_frame_param (XFRAME (frame), Qdisplay_environment_variable);
+  /* For DISPLAY try to get the values from the frame or the initial env.  */
   if (strcmp (var, "DISPLAY") == 0)
-    if (! NILP (display))
-      {
+    {
+      Lisp_Object display
+       = Fframe_parameter (NILP (frame) ? selected_frame : frame, Qdisplay);
+      if (STRINGP (display))
+       {
          *value    = (char *) SDATA (display);
          *valuelen = SBYTES (display);
          return 1;
-      }
-
-  /* Try to find VAR in Vprocess_environment.  */
-  if (getenv_internal_1 (var, varlen, value, valuelen,
-                        Vprocess_environment))
-    return value ? 1 : 0;
-
-#if 0
-  /* Find the environment in which to search the variable. */
-  CHECK_FRAME (frame);
-  frame = Fframe_with_environment (frame);
+       }
+      /* If still not found, Look for DISPLAY in Vinitial_environment.  */
+      if (getenv_internal_1 (var, varlen, value, valuelen,
+                            Vinitial_environment))
+       return *value ? 1 : 0;
+    }
 
-  if (getenv_internal_1 (var, varlen, value, valuelen,
-                        get_frame_param (XFRAME (frame), Qenvironment)))
-    return value ? 1 : 0;
-#endif
   return 0;
 }
 
@@ -1629,7 +1610,7 @@ will simply look up the variable in that frame's environment.  */)
        return Qnil;
     }
   else if (getenv_internal (SDATA (variable), SBYTES (variable),
-                      &value, &valuelen, env))
+                           &value, &valuelen, env))
     return make_string (value, valuelen);
   else
     return Qnil;