Xref: utzoo gnu.emacs.help:1958 comp.emacs:10664 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!sdd.hp.com!wuarchive!uunet!tut.cis.ohio-state.edu!unreplyable!garbage From: tsilva%aaec1.UUCP@DSPVAX.MIT.EDU (Tony Silva) Newsgroups: gnu.emacs.help,comp.emacs Subject: Re: accessing environment variables in Lisp expressions (SUMMARY) Message-ID: <9105071515.AA18931@aaec.com.uucp> Date: 7 May 91 15:15:59 GMT Sender: daemon@tut.cis.ohio-state.edu Followup-To: gnu.emacs.help Organization: Gatewayed from the GNU Project mailing list help-gnu-emacs@prep.ai.mit.edu Lines: 47 I received several excellent suggestions for avoiding hardwiring home directory names, etc., in my ~/.emacs file, as in: (setq mail-archive-file-name "/u/tsilva/SMAIL") The key Lisp functions are "substitute-in-file-name", "expand-file-name", and (I'm embarrassed to say I never thought of this one) "getenv". (I had tried using "command-apropos" and searching through the Emacs topics using Info Reader, but apparently didn't try hard enough.). Any of the following can be used in place of the expression above: (setq mail-archive-file-name (substitute-in-file-name "$HOME/SMAIL")) (setq mail-archive-file-name (expand-file-name "~/SMAIL")) (setq mail-archive-file-name (concat (getenv "HOME") "/SMAIL")) I'm particularly fond of "expand-file-name" since the csh-like tilde expansion permits easy reference of other users' home directories, as well. Another useful tidbit that was mentioned was: (setq host-name (substring (system-name) 0 (string-match "\\." (system-name)))) to yield the base portion of the current system name, ultimately for invoking host-specific code. Many thanks to all those who took the time to respond: haydens%bullwinkle@xn.ll.mit.edu (Hayden Schultz) rms@gnu.ai.mit.edu (Richard Stallman) raymond@math.berkeley.edu (Raymond Chen) Paul Palmer rsw@cs.brown.edu (Bob Weiner) eirik@theory.TN.CORNELL.EDU (Eirik Fuller) mittal@ISI.EDU Hamish Macdonald Jim Hudgens brookler@lentil.Berkeley.EDU (David Brookler) Scott Brim jimb@gnu.ai.mit.edu (Jim Blandy) Olaf Bigalk Tim Bradshaw spencer@spline.eecs.umich.edu Scott Blachowicz mark3@mtfme.att.com (Mark Hord) mike-w@cs.aukuni.ac.nz