comparison src/callproc.c @ 83427:2afc49c9f0c0

Store local environment in frame (not terminal) parameters. * src/callproc.c (child_setup, getenv_internal, Fgetenv_internal): Store the local environment in a frame (not terminal) parameter. Update doc strings. (syms_of_callproc): Update doc strings. (Qenvironment): Moved to frame.c. * lisp/env.el (read-envvar-name, setenv, getenv, environment): Use frame parameters to store the local environment, not terminal parameters. * server.el (server-process-filter): Store the local environment in a frame (not terminal) parameter. Do not try to decode environment strings. * lisp/frame.el (make-frame): Set up the 'environment frame parameter, when needed. * src/frame.c (Qenvironment): Move here from callproc.c. (Fdelete_frame): Don't allow other frames to refer to a deleted frame in their 'environment parameter. (Fframe_with_environment): New function. (syms_of_frame): Defsubr it. Initialize and staticpro Qenvironment. * frame.h (Qenvironment): Declare. * lisp.h (Fframe_with_environment): EXFUN it. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-467
author Karoly Lorentey <lorentey@elte.hu>
date Thu, 29 Dec 2005 04:31:04 +0000
parents 7c7d1f1cb2e7
children 10f26433fe3f
comparison
equal deleted inserted replaced
83426:7c7d1f1cb2e7 83427:2afc49c9f0c0
117 Lisp_Object Vprocess_environment; 117 Lisp_Object Vprocess_environment;
118 118
119 #ifdef DOS_NT 119 #ifdef DOS_NT
120 Lisp_Object Qbuffer_file_type; 120 Lisp_Object Qbuffer_file_type;
121 #endif /* DOS_NT */ 121 #endif /* DOS_NT */
122 Lisp_Object Qenvironment;
123 122
124 /* True iff we are about to fork off a synchronous process or if we 123 /* True iff we are about to fork off a synchronous process or if we
125 are waiting for it. */ 124 are waiting for it. */
126 int synch_process_alive; 125 int synch_process_alive;
127 126
1317 tem = XCDR (tem)) 1316 tem = XCDR (tem))
1318 new_length++; 1317 new_length++;
1319 1318
1320 if (!NILP (Vlocal_environment_variables)) 1319 if (!NILP (Vlocal_environment_variables))
1321 { 1320 {
1322 local = get_terminal_param (FRAME_DEVICE (XFRAME (selected_frame)), 1321 local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
1323 Qenvironment); 1322 Qenvironment);
1324 if (EQ (Vlocal_environment_variables, Qt) 1323 if (EQ (Vlocal_environment_variables, Qt)
1325 && !NILP (local)) 1324 && !NILP (local))
1326 environment = local; 1325 environment = local;
1327 else if (CONSP (local)) 1326 else if (CONSP (local))
1328 { 1327 {
1354 CONSP (tem) && STRINGP (XCAR (tem)); 1353 CONSP (tem) && STRINGP (XCAR (tem));
1355 tem = XCDR (tem)) 1354 tem = XCDR (tem))
1356 new_env = add_env (env, new_env, egetenv (SDATA (XCAR (tem)))); 1355 new_env = add_env (env, new_env, egetenv (SDATA (XCAR (tem))));
1357 1356
1358 /* The rest of the environment (either Vglobal_environment or the 1357 /* The rest of the environment (either Vglobal_environment or the
1359 'environment terminal parameter). */ 1358 'environment frame parameter). */
1360 for (tem = environment; 1359 for (tem = environment;
1361 CONSP (tem) && STRINGP (XCAR (tem)); 1360 CONSP (tem) && STRINGP (XCAR (tem));
1362 tem = XCDR (tem)) 1361 tem = XCDR (tem))
1363 new_env = add_env (env, new_env, SDATA (XCAR (tem))); 1362 new_env = add_env (env, new_env, SDATA (XCAR (tem)));
1364 1363
1486 return new; 1485 return new;
1487 } 1486 }
1488 } 1487 }
1489 1488
1490 static int 1489 static int
1491 getenv_internal (var, varlen, value, valuelen, terminal) 1490 getenv_internal (var, varlen, value, valuelen, frame)
1492 char *var; 1491 char *var;
1493 int varlen; 1492 int varlen;
1494 char **value; 1493 char **value;
1495 int *valuelen; 1494 int *valuelen;
1496 Lisp_Object terminal; 1495 Lisp_Object frame;
1497 { 1496 {
1498 Lisp_Object scan; 1497 Lisp_Object scan;
1499 Lisp_Object environment = Vglobal_environment; 1498 Lisp_Object environment = Vglobal_environment;
1500 1499
1501 /* Try to find VAR in Vprocess_environment first. */ 1500 /* Try to find VAR in Vprocess_environment first. */
1526 } 1525 }
1527 } 1526 }
1528 } 1527 }
1529 1528
1530 /* Find the environment in which to search the variable. */ 1529 /* Find the environment in which to search the variable. */
1531 if (!NILP (terminal)) 1530 if (!NILP (frame))
1532 { 1531 {
1533 Lisp_Object local = get_terminal_param (get_device (terminal, 1), Qenvironment); 1532 CHECK_FRAME (frame);
1533 frame = Fframe_with_environment (frame);
1534 Lisp_Object local = get_frame_param (XFRAME (frame), Qenvironment);
1534 /* Use Vglobal_environment if there is no local environment. */ 1535 /* Use Vglobal_environment if there is no local environment. */
1535 if (!NILP (local)) 1536 if (!NILP (local))
1536 environment = local; 1537 environment = local;
1537 } 1538 }
1538 else if (!NILP (Vlocal_environment_variables)) 1539 else if (!NILP (Vlocal_environment_variables))
1539 { 1540 {
1540 Lisp_Object local = get_terminal_param (FRAME_DEVICE (XFRAME (selected_frame)), 1541 Lisp_Object local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
1541 Qenvironment); 1542 Qenvironment);
1542 if (EQ (Vlocal_environment_variables, Qt) 1543 if (EQ (Vlocal_environment_variables, Qt)
1543 && !NILP (local)) 1544 && !NILP (local))
1544 environment = local; 1545 environment = local;
1545 else if (CONSP (local)) 1546 else if (CONSP (local))
1546 { 1547 {
1592 DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 2, 0, 1593 DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 2, 0,
1593 doc: /* Get the value of environment variable VARIABLE. 1594 doc: /* Get the value of environment variable VARIABLE.
1594 VARIABLE should be a string. Value is nil if VARIABLE is undefined in 1595 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1595 the environment. Otherwise, value is a string. 1596 the environment. Otherwise, value is a string.
1596 1597
1597 If optional parameter TERMINAL is non-nil, then it should be a 1598 If optional parameter FRAME is non-nil, then it should be a frame. If
1598 terminal id or a frame. If the specified terminal device has its own 1599 that frame has its own set of environment variables, this function
1599 set of environment variables, this function will look up VARIABLE in 1600 will look up VARIABLE in there.
1600 it.
1601 1601
1602 Otherwise, this function searches `process-environment' for VARIABLE. 1602 Otherwise, this function searches `process-environment' for VARIABLE.
1603 If it was not found there, then it continues the search in either 1603 If it was not found there, then it continues the search in either
1604 `global-environment' or the local environment list of the current 1604 `global-environment' or the local environment list of the current
1605 terminal device, depending on the value of 1605 frame, depending on the value of `local-environment-variables'. */)
1606 `local-environment-variables'. */) 1606 (variable, frame)
1607 (variable, terminal) 1607 Lisp_Object variable, frame;
1608 Lisp_Object variable, terminal;
1609 { 1608 {
1610 char *value; 1609 char *value;
1611 int valuelen; 1610 int valuelen;
1612 1611
1613 CHECK_STRING (variable); 1612 CHECK_STRING (variable);
1614 if (getenv_internal (SDATA (variable), SBYTES (variable), 1613 if (getenv_internal (SDATA (variable), SBYTES (variable),
1615 &value, &valuelen, terminal)) 1614 &value, &valuelen, frame))
1616 return make_string (value, valuelen); 1615 return make_string (value, valuelen);
1617 else 1616 else
1618 return Qnil; 1617 return Qnil;
1619 } 1618 }
1620 1619
1840 Each element should be a string of the form ENVVARNAME=VALUE. 1839 Each element should be a string of the form ENVVARNAME=VALUE.
1841 1840
1842 The environment which Emacs inherits is placed in this variable when 1841 The environment which Emacs inherits is placed in this variable when
1843 Emacs starts. 1842 Emacs starts.
1844 1843
1845 Some terminal devices may have their own local list of environment 1844 Some frames may have their own local list of environment variables in
1846 variables in their 'environment parameter, which may override this 1845 their 'environment parameter, which may override this global list; see
1847 global list; see `local-environment-variables'. See 1846 `local-environment-variables'. See `process-environment' for a way to
1848 `process-environment' for a way to modify an environment variable on 1847 modify an environment variable on all frames.
1849 all terminals.
1850 1848
1851 If multiple entries define the same variable, the first one always 1849 If multiple entries define the same variable, the first one always
1852 takes precedence. 1850 takes precedence.
1853 1851
1854 Non-ASCII characters are encoded according to the initial value of 1852 Non-ASCII characters are encoded according to the initial value of
1858 DEFVAR_LISP ("process-environment", &Vprocess_environment, 1856 DEFVAR_LISP ("process-environment", &Vprocess_environment,
1859 doc: /* List of overridden environment variables for subprocesses to inherit. 1857 doc: /* List of overridden environment variables for subprocesses to inherit.
1860 Each element should be a string of the form ENVVARNAME=VALUE. 1858 Each element should be a string of the form ENVVARNAME=VALUE.
1861 1859
1862 Entries in this list take precedence to those in `global-environment' 1860 Entries in this list take precedence to those in `global-environment'
1863 or the terminal environment. (See `local-environment-variables' for 1861 or the frame-local environment. (See `local-environment-variables'.)
1864 an explanation of the terminal-local environment.) Therefore, 1862 Therefore, let-binding `process-environment' is an easy way to
1865 let-binding `process-environment' is an easy way to temporarily change 1863 temporarily change the value of an environment variable, irrespective
1866 the value of an environment variable, irrespective of where it comes 1864 of where it comes from. To use `process-environment' to remove an
1867 from. To use `process-environment' to remove an environment variable, 1865 environment variable, include only its name in the list, without
1868 include only its name in the list, without "=VALUE". 1866 "=VALUE".
1869 1867
1870 This variable is set to nil when Emacs starts. 1868 This variable is set to nil when Emacs starts.
1871 1869
1872 If multiple entries define the same variable, the first one always 1870 If multiple entries define the same variable, the first one always
1873 takes precedence. 1871 takes precedence.
1884 defsubr (&Sgetenv_internal); 1882 defsubr (&Sgetenv_internal);
1885 #endif 1883 #endif
1886 defsubr (&Scall_process_region); 1884 defsubr (&Scall_process_region);
1887 1885
1888 DEFVAR_LISP ("local-environment-variables", &Vlocal_environment_variables, 1886 DEFVAR_LISP ("local-environment-variables", &Vlocal_environment_variables,
1889 doc: /* Enable or disable terminal-local environment variables. 1887 doc: /* Enable or disable frame-local environment variables.
1890 If set to t, `getenv', `setenv' and subprocess creation functions use 1888 If set to t, `getenv', `setenv' and subprocess creation functions use
1891 the local environment of the terminal device of the selected frame, 1889 the local environment of the selected frame, ignoring
1892 ignoring `global-environment'. 1890 `global-environment'.
1893 1891
1894 If set to nil, Emacs uses `global-environment' and ignores the 1892 If set to nil, Emacs uses `global-environment' and ignores the
1895 terminal environment. 1893 frame-local environment.
1896 1894
1897 Otherwise, `local-environment-variables' should be a list of variable 1895 Otherwise, `local-environment-variables' should be a list of variable
1898 names (represented by Lisp strings) to look up in the terminal's 1896 names (represented by Lisp strings) to look up in the frame's
1899 environment. The rest will come from `global-environment'. */); 1897 environment. The rest will come from `global-environment'. */);
1900 Vlocal_environment_variables = Qnil; 1898 Vlocal_environment_variables = Qnil;
1901
1902 Qenvironment = intern ("environment");
1903 staticpro (&Qenvironment);
1904 } 1899 }
1905 1900
1906 /* arch-tag: 769b8045-1df7-4d2b-8968-e3fb49017f95 1901 /* arch-tag: 769b8045-1df7-4d2b-8968-e3fb49017f95
1907 (do not change this comment) */ 1902 (do not change this comment) */