diff src/callproc.c @ 83640:2aee92eacdab

* server.el (server-process-filter): Likewise. (server-process-filter): Likewise. Also set COLORFGBG and COLORTERM. * frame.el (frame-initialize, make-frame): Likewise. * faces.el (tty-set-up-initial-frame-faces): Likewise. * env.el (read-envvar-name): Don't consider the environment frame param. (setenv): Set display-environment-variable and term-environment-variable. * frame.c (Qterm_environment_variable, Qdisplay_environment_variable): New variables. (syms_of_frame): Intern and staticpro them. * frame.h: Declare them here. * callproc.c (child_setup): Use the display-environment-variable and term-environment-variable frame params. (getenv_internal): Likewise. (set_initial_environment): Initialise Vprocess_environment. * frames.texi (Basic Parameters): Add display-environment-variable and term-environment-variable.
author Dan Nicolaescu <dann@ics.uci.edu>
date Tue, 03 Jul 2007 04:53:21 +0000
parents 07774e5c3ff5
children 65663fcd2caa
line wrap: on
line diff
--- a/src/callproc.c	Mon Jul 02 02:39:53 2007 +0000
+++ b/src/callproc.c	Tue Jul 03 04:53:21 2007 +0000
@@ -1245,6 +1245,8 @@
 {
   char **env;
   char *pwd_var;
+  char *term_var;
+  char *display_var;
 #ifdef WINDOWSNT
   int cpid;
   HANDLE handles[3];
@@ -1325,9 +1327,12 @@
     register char **new_env;
     char **p, **q;
     register int new_length;
-    Lisp_Object local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
-                                         Qenvironment);
+    Lisp_Object local = selected_frame; /* get_frame_param (XFRAME (Fframe_with_environment (selected_frame)), */
+/*                                          Qenvironment); */
 
+    Lisp_Object term;
+    Lisp_Object display;
+    
     new_length = 0;
 
     for (tem = Vprocess_environment;
@@ -1335,10 +1340,21 @@
          tem = XCDR (tem))
       new_length++;
 
+#if 0    
     for (tem = local;
 	 CONSP (tem) && STRINGP (XCAR (tem));
 	 tem = XCDR (tem))
       new_length++;
+#endif
+
+    /* Add TERM and DISPLAY from the frame local values. */
+    term = get_frame_param (XFRAME (local), Qterm_environment_variable);
+    if (! NILP (term))
+      new_length++;
+
+    display = get_frame_param (XFRAME (local), Qdisplay_environment_variable);
+    if (! NILP (display))
+      new_length++;
 
     /* new_length + 2 to include PWD and terminating 0.  */
     env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
@@ -1348,18 +1364,43 @@
     if (egetenv ("PWD"))
       *new_env++ = pwd_var;
  
+    if (! NILP (term))
+      {
+	int vlen = strlen ("TERM=") + strlen (SDATA (term)) + 1;
+	char *vdata = (char *) alloca (vlen);
+	strcpy (vdata, "TERM=");
+	strcat (vdata, SDATA (term));
+	new_env = add_env (env, new_env, vdata);
+      }
+
+    if (! NILP (display))
+      {
+	int vlen = strlen ("DISPLAY=") + strlen (SDATA (display)) + 1;
+	char *vdata = (char *) alloca (vlen);
+	strcpy (vdata, "DISPLAY=");
+	strcat (vdata, SDATA (display));
+	new_env = add_env (env, new_env, vdata);
+      }
+
     /* Overrides.  */
     for (tem = Vprocess_environment;
 	 CONSP (tem) && STRINGP (XCAR (tem));
 	 tem = XCDR (tem))
-      new_env = add_env (env, new_env, SDATA (XCAR (tem)));
+      {
+	if ((strcmp (SDATA (XCAR (tem)), "TERM") != 0)
+	    && (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.  */
@@ -1373,6 +1414,8 @@
           p++;
       }
   }
+
+  
 #ifdef WINDOWSNT
   prepare_standard_handles (in, out, err, handles);
   set_process_dir (SDATA (current_dir));
@@ -1494,6 +1537,9 @@
      Lisp_Object frame;
 {
   Lisp_Object scan;
+  Lisp_Object term;
+  Lisp_Object display;
+  
 
   if (NILP (frame))
     {
@@ -1528,6 +1574,56 @@
       frame = selected_frame;
     }
 
+  /* For TERM and DISPLAY first try to get the values from the frame. */
+  term = get_frame_param (XFRAME (frame), Qterm_environment_variable);
+  if (strcmp (var, "TERM") == 0)
+    if (! NILP (term))
+      {
+	  *value    = (char *) SDATA (term);
+	  *valuelen = SBYTES (term);
+	  return 1;
+      }
+  display = get_frame_param (XFRAME (frame), Qdisplay_environment_variable);
+  if (strcmp (var, "DISPLAY") == 0)
+    if (! NILP (display))
+      {
+	  *value    = (char *) SDATA (display);
+	  *valuelen = SBYTES (display);
+	  return 1;
+      }
+
+  {
+    /* Try to find VAR in Vprocess_environment.  */
+    for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
+      {
+	Lisp_Object entry = XCAR (scan);
+	if (STRINGP (entry)
+	    && SBYTES (entry) >= varlen
+#ifdef WINDOWSNT
+	    /* NT environment variables are case insensitive.  */
+	    && ! strnicmp (SDATA (entry), var, varlen)
+#else  /* not WINDOWSNT */
+	    && ! bcmp (SDATA (entry), var, varlen)
+#endif /* not WINDOWSNT */
+	    )
+	  {
+	    if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
+	      {
+		*value = (char *) SDATA (entry) + (varlen + 1);
+		*valuelen = SBYTES (entry) - (varlen + 1);
+		return 1;
+	      }
+	    else if (SBYTES (entry) == varlen)
+	      {
+		/* Lone variable names in Vprocess_environment mean that
+		   variable should be removed from the environment. */
+		return 0;
+	      }
+	  }
+      }
+  }
+
+#if 0
   /* Find the environment in which to search the variable. */
   CHECK_FRAME (frame);
   frame = Fframe_with_environment (frame);
@@ -1555,7 +1651,7 @@
 	  return 1;
 	}
     }
-
+#endif
   return 0;
 }
 
@@ -1737,14 +1833,15 @@
 set_initial_environment ()
 {
   register char **envp;
-  Lisp_Object env = Qnil;
+  Lisp_Object env = Vprocess_environment;
 #ifndef CANNOT_DUMP
   if (initialized)
 #endif
     {
       for (envp = environ; *envp; envp++)
-        env = Fcons (build_string (*envp), env);
-      store_frame_param (SELECTED_FRAME(), Qenvironment, env);
+	Vprocess_environment = Fcons (build_string (*envp),
+				      Vprocess_environment);
+      store_frame_param (SELECTED_FRAME(), Qenvironment, Vprocess_environment);
     }
 }