reddit / emacs

At which stage in the Emacs startup sequence does the $HOST environment variable become available to Emacs?

vfclists · 2022-09-26 10:02
I've got an environment variable called $HOST and it seems that Emacs doesn't read it early enough. It usually isn't available during the execution of `init.el` It s present in the environment frm which I run Emacs. `(getenv "HOST")` returns a blank and it is annoying as my `custom-file` includes the `USER` and `HOST` variables so I can use the same configuration on different systems without clobbering the `custom.el`. Once Emacs fully loads it is available and `(getenv "HOST")` works fine. Is there some reason Emacs behaves this way for this particular variable? **SOLVED** I checked my `.profile` and realized that in this instance the config file which creates the `HOST` variable was not being `source`'d, so I've fixed it in this instance. The problem dates back some years ago when the default Debian environment was not creating a variable I needed so I had to add `export HOST=$(hostname)` to my `.profile` to ensure it would be available to GUI programs.
susanne-o · 2022-09-26 11:19
I'd suspect something trivial like "printer cable not connected" when the printer doesn't work. is HOST exported to child processes in your shell? i.e. is HOST in initial-environment on your system? you can check that by entering the debugger in your init.el add (debug) to your init.el and a `--debug-init` argument on the command line. https://www.gnu.org/software/emacs/manual/html_node/elisp/System-Environment.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Explicit-Debug.html
seishuuu · 2022-09-26 11:25
while this does not answer your initial question about the behavior, I use `(system-name)` and `(system-type)` to do such configuration.
arthurno1 · 2022-09-26 12:10
As suggested, by others (system-name) is probably what you are looking for. C-h f system-name RET > > system-name is a built-in function in ‘C source code’. > > (system-name) > > Return the host name of the machine you are running on, as a string. > > Probably introduced at or before Emacs version 19.23.
vfclists · 2022-09-26 12:24
I think I will switch to `(system-name)` for the future. BTW `system-type` is a variable not a function.
vfclists · 2022-09-26 12:24
I checked it and realized that in this instance the config file which creates the `HOST` variable was not being `source`'d, so I've fixed it in this instance. The problem dates back some years ago when the default Debian environment was not creating a variable I needed so I had to add `export HOST=$(hostname)` to my `.profile` to ensure it would be available to GUI programs.
susanne-o · 2022-09-26 12:31
see, printer was simply not plugged in ;-) thanks for the update.
yurikhan · 2022-09-26 14:51
I seem to remember `export VAR=VALUE` is a bashism so can’t portably be used in `.profile` which is a POSIX-standardized file. You’re supposed to say `VAR=VALUE` and `export VAR` separately.
DrPiwi · 2022-09-26 15:07
Why not use the standard `$HOSTNAME` variable that is set automatically?
mmaug · 2022-09-26 17:42
`VAR=VAL; export VAR` should be portable
vfclists · 2022-09-26 19:10
I set it some years ago. I can't remember the reason why but I think back then HOSTNAME was not appropriate or conflicted with something else.