changeset 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 b9b616870be8
children 5a99c88f9d9f
files lisp/ChangeLog.multi-tty lisp/env.el lisp/faces.el lisp/frame.el lisp/server.el lispref/ChangeLog.multi-tty lispref/frames.texi src/ChangeLog.multi-tty src/callproc.c src/frame.c src/frame.h
diffstat 11 files changed, 219 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog.multi-tty	Mon Jul 02 02:39:53 2007 +0000
+++ b/lisp/ChangeLog.multi-tty	Tue Jul 03 04:53:21 2007 +0000
@@ -1,5 +1,18 @@
 2007-07-02  Dan Nicolaescu  <dann@ics.uci.edu>
 
+	* 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.
+
 	* term/x-win.el (x-menu-bar-open): Use accelerate-menu.
 
 2007-06-23  Dan Nicolaescu  <dann@ics.uci.edu>
--- a/lisp/env.el	Mon Jul 02 02:39:53 2007 +0000
+++ b/lisp/env.el	Tue Jul 03 04:53:21 2007 +0000
@@ -55,7 +55,8 @@
 				     (substring enventry 0
 						(string-match "=" enventry)))))
 			   (append process-environment
-				   (frame-parameter (frame-with-environment) 'environment)))
+				   nil ;;(frame-parameter (frame-with-environment) 'environment)
+				   ))
 		   nil mustmatch nil 'read-envvar-name-history))
 
 ;; History list for VALUE argument to setenv.
@@ -191,9 +192,14 @@
       (setq process-environment (setenv-internal process-environment
 						 variable value t))
     (setq frame (frame-with-environment frame))
-    (set-frame-parameter frame 'environment
-			 (setenv-internal (frame-parameter frame 'environment)
-					  variable value nil)))
+    (cond 
+     ((string-equal "TERM" variable)
+      (set-frame-parameter frame 'term-environment-variable value))
+     ((string-equal "DISPLAY" variable)
+      (set-frame-parameter frame 'display-environment-variable value))
+     (t 
+      (setq process-environment (setenv-internal process-environment
+						 variable value nil)))))
   value)
 
 (defun getenv (variable &optional frame)
@@ -238,8 +244,8 @@
 `locale-coding-system', i.e. the elements must normally be decoded for use.
 See `setenv' and `getenv'."
   (let* ((env (append process-environment
-		      (frame-parameter (frame-with-environment frame)
-				       'environment)
+;; 		      (frame-parameter (frame-with-environment frame)
+;; 				       'environment)
 		      nil))
 	 (scan env)
 	 prev seen)
--- a/lisp/faces.el	Mon Jul 02 02:39:53 2007 +0000
+++ b/lisp/faces.el	Tue Jul 03 04:53:21 2007 +0000
@@ -1909,7 +1909,11 @@
 (defun tty-set-up-initial-frame-faces ()
   (let ((frame (selected-frame)))
     (frame-set-background-mode frame)
-    (face-set-after-frame-default frame)))
+    (face-set-after-frame-default frame)
+    (set-frame-parameter frame-initial-frame 'term-environment-variable
+			 (getenv "TERM"))
+    (set-frame-parameter frame-initial-frame 'display-environment-variable
+			 (getenv "DISPLAY"))))
 
 
 
--- a/lisp/frame.el	Mon Jul 02 02:39:53 2007 +0000
+++ b/lisp/frame.el	Tue Jul 03 04:53:21 2007 +0000
@@ -241,6 +241,10 @@
 	;; Copy the environment of the Emacs process into the new frame.
 	(set-frame-parameter frame-initial-frame 'environment
 			     (frame-parameter terminal-frame 'environment))
+	(set-frame-parameter frame-initial-frame 'term-environment-variable
+			     (getenv "TERM"))
+	(set-frame-parameter frame-initial-frame 'display-environment-variable
+			     (getenv "DISPLAY"))
 	;; At this point, we know that we have a frame open, so we
 	;; can delete the terminal frame.
 	(delete-frame terminal-frame)
@@ -700,11 +704,17 @@
     (normal-erase-is-backspace-setup-frame frame)
     ;; Inherit the 'environment and 'client parameters.
     (let ((env (frame-parameter oldframe 'environment))
-	  (client (frame-parameter oldframe 'client)))
+	  (client (frame-parameter oldframe 'client))
+	   (termenv (frame-parameter oldframe 'term-environment-variable))
+	   (displayenv (frame-parameter oldframe 'display-environment-variable)))
       (if (not (framep env))
 	  (setq env oldframe))
       (if (and env (not (assq 'environment parameters)))
 	  (set-frame-parameter frame 'environment env))
+      (if (and termenv (not (assq 'term-environment-variable parameters)))
+	  (set-frame-parameter frame 'term-environment-variable termenv))
+      (if (and displayenv (not (assq 'display-environment-variable parameters)))
+	  (set-frame-parameter frame 'display-environment-variable displayenv))
       (if (and client (not (assq 'client parameters)))
 	  (set-frame-parameter frame 'client client)))
     (run-hook-with-args 'after-make-frame-functions frame)
--- a/lisp/server.el	Mon Jul 02 02:39:53 2007 +0000
+++ b/lisp/server.el	Tue Jul 03 04:53:21 2007 +0000
@@ -763,6 +763,10 @@
 			  ;; initialization parameters for X frames at
 			  ;; the moment.
 			  (modify-frame-parameters frame params)
+			  (set-frame-parameter frame 'display-environment-variable 
+					       (server-getenv-from env "DISPLAY"))
+			  (set-frame-parameter frame 'term-environment-variable 
+					       (server-getenv-from env "TERM"))
 			  (select-frame frame)
 			  (server-client-set client 'frame frame)
 			  (server-client-set client 'terminal (frame-terminal frame))
@@ -812,12 +816,19 @@
 			    "BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES"
 			    "NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING"
 			    "NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO"
-			    "TERMINFO_DIRS" "TERMPATH")
+			    "TERMINFO_DIRS" "TERMPATH" 
+			    ;; rxvt wants these
+			    "COLORFGBG" "COLORTERM")
 			(setq frame (make-frame-on-tty tty type
 						       ;; Ignore nowait here; we always need to clean
 						       ;; up opened ttys when the client dies.
 						       `((client . ,proc)
 							 (environment . ,env)))))
+	      
+		      (set-frame-parameter frame 'display-environment-variable 
+					   (server-getenv-from env "DISPLAY"))
+		      (set-frame-parameter frame 'term-environment-variable 
+					   (server-getenv-from env "TERM"))
 		      (select-frame frame)
 		      (server-client-set client 'frame frame)
 		      (server-client-set client 'tty (terminal-name frame))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lispref/ChangeLog.multi-tty	Tue Jul 03 04:53:21 2007 +0000
@@ -0,0 +1,30 @@
+2007-07-02  Dan Nicolaescu  <dann@ics.uci.edu>
+
+	* frames.texi (Basic Parameters): Add display-environment-variable
+	and term-environment-variable.
+
+;; Local Variables:
+;; coding: iso-2022-7bit
+;; add-log-time-zone-rule: t
+;; End:
+	
+    Copyright (C) 2007 Free Software Foundation, Inc.
+
+  This file is part of GNU Emacs.
+
+  GNU Emacs is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2, or (at your option)
+  any later version.
+
+  GNU Emacs is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with GNU Emacs; see the file COPYING.  If not, write to the
+  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  Boston, MA 02110-1301, USA.
+
+
--- a/lispref/frames.texi	Mon Jul 02 02:39:53 2007 +0000
+++ b/lispref/frames.texi	Tue Jul 03 04:53:21 2007 +0000
@@ -378,6 +378,14 @@
 If you specify the frame name explicitly when you create the frame, the
 name is also used (instead of the name of the Emacs executable) when
 looking up X resources for the frame.
+
+@item display-environment-variable
+The value of the @code{DISPLAY} environment variable for the frame. It
+is passed to child processes.
+
+@item term-environment-variable
+The value of the @code{TERM} environment variable for the frame. It
+is passed to child processes.
 @end table
 
 @node Position Parameters
--- a/src/ChangeLog.multi-tty	Mon Jul 02 02:39:53 2007 +0000
+++ b/src/ChangeLog.multi-tty	Tue Jul 03 04:53:21 2007 +0000
@@ -1,3 +1,16 @@
+2007-07-02  Dan Nicolaescu  <dann@ics.uci.edu>
+
+	* 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.
+
 2007-06-03  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* xselect.c (x_handle_selection_clear): Only access
--- 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);
     }
 }
 
--- a/src/frame.c	Mon Jul 02 02:39:53 2007 +0000
+++ b/src/frame.c	Tue Jul 03 04:53:21 2007 +0000
@@ -111,6 +111,8 @@
 Lisp_Object Qtty, Qtty_type;
 Lisp_Object Qwindow_system;
 Lisp_Object Qenvironment;
+Lisp_Object Qterm_environment_variable;
+Lisp_Object Qdisplay_environment_variable;
 
 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
 
@@ -4353,7 +4355,12 @@
   staticpro (&Qwindow_system);
   Qenvironment = intern ("environment");
   staticpro (&Qenvironment);
-  
+
+  Qterm_environment_variable = intern ("term-environment-variable");
+  staticpro (&Qterm_environment_variable);
+  Qdisplay_environment_variable = intern ("display-environment-variable");
+  staticpro (&Qdisplay_environment_variable);
+
   Qface_set_after_frame_default = intern ("face-set-after-frame-default");
   staticpro (&Qface_set_after_frame_default);
 
--- a/src/frame.h	Mon Jul 02 02:39:53 2007 +0000
+++ b/src/frame.h	Tue Jul 03 04:53:21 2007 +0000
@@ -780,6 +780,8 @@
 extern Lisp_Object Qtty, Qtty_type;
 extern Lisp_Object Qterminal, Qterminal_live_p;
 extern Lisp_Object Qenvironment;
+extern Lisp_Object Qterm_environment_variable;
+extern Lisp_Object Qdisplay_environment_variable;
 
 extern struct frame *last_nonminibuf_frame;