unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* updating shell environment variables
@ 2004-11-05 14:49 Dan Elliott
  2004-11-05 15:50 ` Kevin Rodgers
  2004-11-05 17:07 ` Thien-Thi Nguyen
  0 siblings, 2 replies; 8+ messages in thread
From: Dan Elliott @ 2004-11-05 14:49 UTC (permalink / raw)


Hello,

If I need to change a few environment variables, must I exit and restart
emacs for these to take effect?  I typically run emacs with the -nw switch
and then suspend emacs when I need to change env. variables.  Is there a
better way?  Having to restart emacs is a major pain!

Thank you,

Dan Elliott

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: updating shell environment variables
  2004-11-05 14:49 updating shell environment variables Dan Elliott
@ 2004-11-05 15:50 ` Kevin Rodgers
  2004-11-05 17:09   ` Dan Elliott
  2004-11-05 17:07 ` Thien-Thi Nguyen
  1 sibling, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2004-11-05 15:50 UTC (permalink / raw)


Dan Elliott wrote:
 > If I need to change a few environment variables, must I exit and restart
 > emacs for these to take effect?  I typically run emacs with the -nw 
switch
 > and then suspend emacs when I need to change env. variables.  Is there a
 > better way?  Having to restart emacs is a major pain!

M-x setenv

I guess `C-h a env RET' was too painful to even try.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: updating shell environment variables
  2004-11-05 14:49 updating shell environment variables Dan Elliott
  2004-11-05 15:50 ` Kevin Rodgers
@ 2004-11-05 17:07 ` Thien-Thi Nguyen
  1 sibling, 0 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2004-11-05 17:07 UTC (permalink / raw)


"Dan Elliott" <dan_elliott_at_cox_dot_net@noSpam.org> writes:

> If I need to change a few environment variables, must I exit and
> restart emacs for these to take effect?  I typically run emacs with
> the -nw switch and then suspend emacs when I need to change
> env. variables.  Is there a better way?  Having to restart emacs is a
> major pain!

if the env vars are only for use in emacs (for the benefit of
subprocesses started from within emacs, or for substitution in a
buffer-list or in a `M-x find-file' command), you can try jamenv.el:

http://www.glug.org/people/ttn/software/ttn-pers-elisp/dist/
       lisp/low-stress/jamenv.el

(note: url split into two lines.)  to try it out, after loading
jamenv.el, create a buffer w/ contents, for example:

  ;; cancellare
  - PWD
  - OLDPWD
  - PAGER
  
  ;; impostare
  b               ~/build
  td              ~/build/tastiera-dura
  e               ~/build/emacs
  g               ~/build/hack/guile-core
  s               ~/local/src
  www             ~/public_html

then do `M-x jamenv-buffer' in that buffer.  you can verify things
are working by looking at the value of the `process-environment'
elisp variable.  you can save this buffer to a file and apply
`jamenv-from-file' to the filename on startup.  if the file
contents should change, simply re-invoke `jamenv-from-file'
manually to update emacs' notion of env vars.

(you are right.  IMHO, leaving emacs is both sick AND wrong! ;-)

thi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: updating shell environment variables
  2004-11-05 15:50 ` Kevin Rodgers
@ 2004-11-05 17:09   ` Dan Elliott
  2004-11-05 18:37     ` Kevin Rodgers
  2004-11-05 19:27     ` Pascal Bourguignon
  0 siblings, 2 replies; 8+ messages in thread
From: Dan Elliott @ 2004-11-05 17:09 UTC (permalink / raw)



"Kevin Rodgers" <ihs_4664@yahoo.com> wrote in message
news:2v1lq9F2gfd06U1@uni-berlin.de...
> Dan Elliott wrote:
>  > If I need to change a few environment variables, must I exit and
restart
>  > emacs for these to take effect?  I typically run emacs with the -nw
> switch
>  > and then suspend emacs when I need to change env. variables.  Is there
a
>  > better way?  Having to restart emacs is a major pain!
>
> M-x setenv
>
> I guess `C-h a env RET' was too painful to even try.
>
> -- 
> Kevin Rodgers

Thank you Kevin Rodgers, for your response plus commentary.  I apologize for
the poor wording in my original post, the question looks quite stupid.
Sorry for wasting your time.

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?

Thank you (again) for any assistance,

Dan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: updating shell environment variables
  2004-11-05 17:09   ` Dan Elliott
@ 2004-11-05 18:37     ` Kevin Rodgers
  2004-11-05 19:45       ` Pascal Bourguignon
  2004-11-05 19:27     ` Pascal Bourguignon
  1 sibling, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2004-11-05 18:37 UTC (permalink / raw)


Dan Elliott wrote:
 > 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?

Like this?

# in the shell:
env | awk -F= '{print "(setenv \"" $1 "\" \"" $2 "\")" }' > /tmp/env.el

; in emacs:
(load-file "/tmp/env.el")

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: updating shell environment variables
  2004-11-05 17:09   ` Dan Elliott
  2004-11-05 18:37     ` Kevin Rodgers
@ 2004-11-05 19:27     ` Pascal Bourguignon
  2004-11-05 19:53       ` Johan Bockgård
  1 sibling, 1 reply; 8+ messages in thread
From: Pascal Bourguignon @ 2004-11-05 19:27 UTC (permalink / raw)


"Dan Elliott" <dan_elliott_at_cox_dot_net@noSpam.org> 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__

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: updating shell environment variables
  2004-11-05 18:37     ` Kevin Rodgers
@ 2004-11-05 19:45       ` Pascal Bourguignon
  0 siblings, 0 replies; 8+ messages in thread
From: Pascal Bourguignon @ 2004-11-05 19:45 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Dan Elliott wrote:
>  > 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?
> 
> Like this?
> 
> # in the shell:
> env | awk -F= '{print "(setenv \"" $1 "\" \"" $2 "\")" }' > /tmp/env.el

It won't work when there are double-quotes or new-lines in the values
or the variables (although shell syntax forbid it, a program could
create such a variable before forking the shell).

> ; in emacs:
> (load-file "/tmp/env.el")
> 
> -- 
> Kevin Rodgers

-- 
__Pascal Bourguignon__

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: updating shell environment variables
  2004-11-05 19:27     ` Pascal Bourguignon
@ 2004-11-05 19:53       ` Johan Bockgård
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Bockgård @ 2004-11-05 19:53 UTC (permalink / raw)


Pascal Bourguignon <spam@mouse-potato.com> writes:

> All emacs _commands_ are _functions_ too.

<nitpick>

"command"
     A "command" is an object that `command-execute' can invoke; it is
     a possible definition for a key sequence. Some functions are
     commands; a function written in Lisp is a command if it contains
     an interactive declaration (*note Defining Commands::). Such a
     function can be called from Lisp expressions like other
     functions; in this case, the fact that the function is a command
     makes no difference.

     Keyboard macros (strings and vectors) are commands also, even
     though they are not functions. A symbol is a command if its
     function definition is a command; such symbols can be invoked
     with `M-x'. The symbol is a function as well if the definition is
     a function. *Note Command Overview::.

(info "(elisp)What Is a Function")

</nitpick>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-11-05 19:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-05 14:49 updating shell environment variables Dan Elliott
2004-11-05 15:50 ` Kevin Rodgers
2004-11-05 17:09   ` Dan Elliott
2004-11-05 18:37     ` Kevin Rodgers
2004-11-05 19:45       ` Pascal Bourguignon
2004-11-05 19:27     ` Pascal Bourguignon
2004-11-05 19:53       ` Johan Bockgård
2004-11-05 17:07 ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).