unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* enviromental variables into dot.emacs
@ 2011-08-14 15:50 daniele.g
  2011-08-14 16:07 ` Tassilo Horn
  2011-08-14 16:07 ` Michael Markert
  0 siblings, 2 replies; 9+ messages in thread
From: daniele.g @ 2011-08-14 15:50 UTC (permalink / raw)
  To: help-gnu-emacs

Can I put enviromental variables in my .emacs file? How?

Thanks in advance.
-- 
        "Come va?".
        "Bene, grazie.  E tu?".
        "Medio".  Cosi' diceva sempre.
        		-- Enrico Brizzi, Jack Frusciante e' uscito dal gruppo




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

* Re: enviromental variables into dot.emacs
  2011-08-14 15:50 enviromental variables into dot.emacs daniele.g
@ 2011-08-14 16:07 ` Tassilo Horn
  2011-08-14 20:12   ` daniele.g
  2011-08-14 16:07 ` Michael Markert
  1 sibling, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2011-08-14 16:07 UTC (permalink / raw)
  To: help-gnu-emacs

dgiglio@iol.it (daniele.g) writes:

Hi Daniele,

> Can I put enviromental variables in my .emacs file?

Sure you can.

> How?

,----[ C-h f setenv RET ]
| setenv is an interactive compiled Lisp function in `env.el'.
| 
| (setenv VARIABLE &optional VALUE SUBSTITUTE-ENV-VARS)
| 
| Set the value of the environment variable named VARIABLE to VALUE.
| VARIABLE should be a string.  VALUE is optional; if not provided or
| nil, the environment variable VARIABLE will be removed.
| 
| Interactively, a prefix argument means to unset the variable, and
| otherwise the current value (if any) of the variable appears at
| the front of the history list when you type in the new value.
| This function always replaces environment variables in the new
| value when called interactively.
| 
| SUBSTITUTE-ENV-VARS, if non-nil, means to substitute environment
| variables in VALUE with `substitute-env-vars', which see.
| This is normally used only for interactive calls.
| 
| The return value is the new value of VARIABLE, or nil if
| it was removed from the environment.
| 
| This function works by modifying `process-environment'.
| 
| As a special case, setting variable `TZ' calls `set-time-zone-rule' as
| a side-effect.
`----

HTH,
Tassilo




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

* Re: enviromental variables into dot.emacs
  2011-08-14 15:50 enviromental variables into dot.emacs daniele.g
  2011-08-14 16:07 ` Tassilo Horn
@ 2011-08-14 16:07 ` Michael Markert
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Markert @ 2011-08-14 16:07 UTC (permalink / raw)
  To: daniele.g; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 123 bytes --]

On 14 Aug 2011, daniele g. wrote:

> Can I put enviromental variables in my .emacs file? How?

Yes, use `setenv`.

Michael

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

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

* Re: enviromental variables into dot.emacs
  2011-08-14 16:07 ` Tassilo Horn
@ 2011-08-14 20:12   ` daniele.g
  2011-08-14 20:28     ` Michael Markert
  2011-08-14 21:46     ` Jay Belanger
  0 siblings, 2 replies; 9+ messages in thread
From: daniele.g @ 2011-08-14 20:12 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn <tassilo@member.fsf.org> writes:

> Dgiglio@iol.it (daniele.g) writes:
>
> Hi Daniele,

Hi Tassilo

There was a misunderstanding. I don't want to set an enviromental
variable, I want to _read_ it. For example, I want set up my email address
for Gnus from $USER and $HOSTNAME values. I know I can use getenv to
read them, but I don't know how to use them in my dot-emacs.

My aim is to unify my conf files making them picking as many values as
possible from the same place.
-- 
                 Tutti per uno, uno per tutti.
                 		-- Dumas padre, "I tre moschettieri"




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

* Re: enviromental variables into dot.emacs
  2011-08-14 20:12   ` daniele.g
@ 2011-08-14 20:28     ` Michael Markert
  2011-08-15  8:47       ` daniele.g
  2011-08-14 21:46     ` Jay Belanger
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Markert @ 2011-08-14 20:28 UTC (permalink / raw)
  To: daniele.g; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 952 bytes --]

On 14 Aug 2011, daniele g. wrote:

> There was a misunderstanding. I don't want to set an enviromental
> variable, I want to _read_ it. For example, I want set up my email
> address for Gnus from $USER and $HOSTNAME values. I know I can use
> getenv to read them, but I don't know how to use them in my dot-emacs.
>
> My aim is to unify my conf files making them picking as many values as
> possible from the same place.

Do you think of this?
#+begin_src emacs-lisp
(cond
((and (string= (getenv "USER") "johndoe")
      (string= (getenv "HOSTNAME") "bar"))
 (setq user-mail-address "johndow@bar.com")
 (require 'john))
((and (string= (getenv "USER") "janedoe")
      (string= (getenv "HOSTNAME") "bar"))
 (setq user-mail-address "johndow@bar.com")
 (require 'jane))
(t
 (setq user-mail-address (concat (getenv "USER") "@" (getenv "HOSTNAME")))))
#+end_src emacs-lisp

But note that $HOSTNAME is often not set. You can use `system-name'
here.

Michael

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

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

* Re: enviromental variables into dot.emacs
  2011-08-14 20:12   ` daniele.g
  2011-08-14 20:28     ` Michael Markert
@ 2011-08-14 21:46     ` Jay Belanger
  2011-08-14 23:35       ` daniele.g
  1 sibling, 1 reply; 9+ messages in thread
From: Jay Belanger @ 2011-08-14 21:46 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: jay.p.belanger


> My aim is to unify my conf files making them picking as many values as
> possible from the same place.

Same here.  I have COMPUTERNAME set to different values on different
computers, so my init file contains

(cond ((string= (getenv "COMPUTERNAME") "home")
       ... home computer specific stuff ...)
      ((string= (getenv "COMPUTERNAME") "office")
       ... office computer specific stuff ...)
      ((string= (getenv "COMPUTERNAME") "netbook")
       ... netbook specific stuff ...))





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

* Re: enviromental variables into dot.emacs
  2011-08-14 21:46     ` Jay Belanger
@ 2011-08-14 23:35       ` daniele.g
  2011-08-15  0:01         ` Jay Belanger
  0 siblings, 1 reply; 9+ messages in thread
From: daniele.g @ 2011-08-14 23:35 UTC (permalink / raw)
  To: help-gnu-emacs

Jay Belanger <jay.p.belanger@gmail.com> writes:

>> My aim is to unify my conf files making them picking as many values as
>> possible from the same place.
>
> Same here.  I have COMPUTERNAME set to different values on different
> computers, so my init file contains
>
> (Cond ((string= (getenv "COMPUTERNAME") "home")
>        ... home computer specific stuff ...)
>       ((String= (getenv "COMPUTERNAME") "office")
>        ... office computer specific stuff ...)
>       ((String= (getenv "COMPUTERNAME") "netbook")
>        ... netbook specific stuff ...))

Forgive me, but my elisp skills are quite low. Can I use a syntax like
this?

(setq var (getenv $VAR))
-- 
  Era cosi' povero che non poteva neanche permettersi di regalare uno
  yo-yo al suo bambino per Natale.  Fece in modo di regalargli uno yo.
  		-- Martin Kauffman




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

* Re: enviromental variables into dot.emacs
  2011-08-14 23:35       ` daniele.g
@ 2011-08-15  0:01         ` Jay Belanger
  0 siblings, 0 replies; 9+ messages in thread
From: Jay Belanger @ 2011-08-15  0:01 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: jay.p.belanger


> Forgive me, but my elisp skills are quite low. Can I use a syntax like
> this?
>
> (setq var (getenv $VAR))

It will have to be (getenv "VAR"), and var will then be a string.




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

* Re: enviromental variables into dot.emacs
  2011-08-14 20:28     ` Michael Markert
@ 2011-08-15  8:47       ` daniele.g
  0 siblings, 0 replies; 9+ messages in thread
From: daniele.g @ 2011-08-15  8:47 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Markert <markert.michael@googlemail.com> writes:

> On 14 Aug 2011, daniele g. wrote:
>
>> There was a misunderstanding. I don't want to set an enviromental
>> variable, I want to _read_ it. For example, I want set up my email
>> address for Gnus from $USER and $HOSTNAME values. I know I can use
>> getenv to read them, but I don't know how to use them in my dot-emacs.
>>
>> My aim is to unify my conf files making them picking as many values as
>> possible from the same place.
>
> Do you think of this?

Oh yesss!

> #+Begin_src emacs-lisp
> (cond
> ((and (string= (getenv "USER") "johndoe")
>       (string= (getenv "HOSTNAME") "bar"))
>  (setq user-mail-address "johndow@bar.com")
>  (require 'john))
> ((and (string= (getenv "USER") "janedoe")
>       (string= (getenv "HOSTNAME") "bar"))
>  (setq user-mail-address "johndow@bar.com")
>  (require 'jane))
> (t
>  (setq user-mail-address (concat (getenv "USER") "@" (getenv "HOSTNAME")))))
> #+end_src emacs-lisp
>
> But note that $HOSTNAME is often not set. You can use `system-name'
> here.

Indeed, the hostname can be recall using the program hostname. This is
the further step, using shell commands within the file. :-)
-- 
                  - Grazie al cielo, ha lavoro.  Chi?
                  - L'astronomo!!




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

end of thread, other threads:[~2011-08-15  8:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-14 15:50 enviromental variables into dot.emacs daniele.g
2011-08-14 16:07 ` Tassilo Horn
2011-08-14 20:12   ` daniele.g
2011-08-14 20:28     ` Michael Markert
2011-08-15  8:47       ` daniele.g
2011-08-14 21:46     ` Jay Belanger
2011-08-14 23:35       ` daniele.g
2011-08-15  0:01         ` Jay Belanger
2011-08-14 16:07 ` Michael Markert

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).