Thanks in advance.
--
"Come va?".
"Bene, grazie. E tu?".
"Medio". Cosi' diceva sempre.
-- Enrico Brizzi, Jack Frusciante e' uscito dal gruppo
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
> Dgi...@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"
> Tassilo Horn <tas...@member.fsf.org> writes:
>
>> Dgi...@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.
(getenv "USER") and such should work in your .emacs file.
> My aim is to unify my conf files making them picking as many values as
> possible from the same place.
That's a good goal.
Jason
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 ...))
> 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.
Not that I still have email addresses that are so contructible,
but the code would be something like (code not tested):
(setq user-mail-address (concat (getenv "USER") "@" (getenv "HOSTNAME")))
-- Bill
>> 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
It will have to be (getenv "VAR"), and var will then be a string.
Depends on what you wan to do with them.
BTW, instead of (getenv "USER") you can use `user-login-name' and
instead of (getenv "HOSTNAME") you may prefer to use `system-name'.
Stefan
> 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 "joh...@bar.com")
(require 'john))
((and (string= (getenv "USER") "janedoe")
(string= (getenv "HOSTNAME") "bar"))
(setq user-mail-address "joh...@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
> 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 "joh...@bar.com")
> (require 'john))
> ((and (string= (getenv "USER") "janedoe")
> (string= (getenv "HOSTNAME") "bar"))
> (setq user-mail-address "joh...@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!!