From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: updating shell environment variables Date: 05 Nov 2004 20:27:52 +0100 Organization: [posted via Easynet Spain] Message-ID: <87hdo4qeo7.fsf@naiad.informatimago.com> References: <2v1lq9F2gfd06U1@uni-berlin.de> <1tOid.10$CR4.1@dfw-service2.ext.ray.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1099683133 8156 80.91.229.6 (5 Nov 2004 19:32:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 5 Nov 2004 19:32:13 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 05 20:32:02 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CQ9oW-0003Mo-00 for ; Fri, 05 Nov 2004 20:32:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CQ9wj-0006Nw-Vp for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Nov 2004 14:40:30 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!newsfeed.freenet.de!newsfeed.wirehub.nl!easynet-monga!easynet.net!easynet-post2!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Original-Lines: 61 Original-NNTP-Posting-Host: 62.93.174.76 Original-X-Trace: DXC=JL\52[^NG@ZNka66i]iEDU>V:nI?;b`^\K;bf[9]X;C] Original-Xref: shelby.stanford.edu gnu.emacs.help:126380 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:21769 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:21769 "Dan Elliott" writes: > Kevin Rodgers wrote: > > I guess `C-h a env RET' was too painful to even try. I prefer to write: M-x apropos RET env RET > My intended question is a bit more complicated. Change the above from "few" > to "nearly one-hundred." I have failed to discover an effective way to do > this. Can I somehow *flash* the state of emacs' environment variables to be > in line with the shell that "owns" my current emacs session? All emacs _commands_ are _functions_ too. M-x setenv RET variable RET value RET <==> (setenv variable value) in a .el Depending on how you store your nearly one-hundred variable/value, you can write a loop to iteratively setenv them. The fundamental mechanism of environment variables is that each process has its onw set, there's no sharing. When a process forks a child, all its environment variables are _copied_ into the child process, which inherit the same values, and that is the ONLY automatic mechanism of communication of environment variables. Once forked, the processes are entirely independent with respect to their environment variables. Now, you seem to be changing the environment variables in one process (a shell) (it does not matter whether it's the parent or a stranger process), and want to get the same environment into another process (your emacs). >>From a shell you can easily collect the environment with the env(1) command. Once again, was it so difficult to use apropos(1)? Perhaps you'll get a hint at some pattern here: M-x apropos RET env RET in emacs apropos env RET in shell For example, you can put the current environment variables into a file: $ env > ~/current-environment Then you can easily enough read this file from emacs, parse it and setenv. Perhaps you want to remove environment variables that are not present in the imported environment. Unfortunately, it seems that it's not possible to gather the list of all environment variables from elisp. You'd have to modify the source of emacs, or launch it from a wrapper to know the original list of environment variables. There may be problems if some environment values contain some NEWLINE, then you'd have to write your own environment dumping program. By the way, it may be easier to write a small C program that will dump the environment variable directly as an elisp source containing lines of: (setenv "var" "val") that you would just load from emacs. (No need to parse, just to escape correcly the variables and the values strings). -- __Pascal Bourguignon__