[comp.emacs] Accessing $HOME in Emacs

worley@compass.com (Dale Worley) (05/06/91)

       (setq mail-archive-file-name "$HOME/SMAIL.tmp")

There are two ways.  The first is to use the function getenv:

    getenv:
    Return the value of environment variable VAR, as a string.
    When invoked interactively, print the value in the echo area.
    VAR is a string, the name of the variable,
     or the symbol t, meaning to return an alist representing the
     current environment.

However, getenv is available only if MAINTAIN_ENVIRONMENT is set in
config.h, at least in Emacs 18.53.

Probably the better way is to use expand-file-name or
substitute-in-file-name:

    expand-file-name:
    Convert FILENAME to absolute, and canonicalize it.
    Second arg DEFAULT is directory to start with if FILENAME is relative
     (does not start with slash); if DEFAULT is nil or missing,
    the current buffer's value of default-directory is used.
    Filenames containing . or .. as components are simplified;
    initial ~ is expanded.  See also the function  substitute-in-file-name.

    substitute-in-file-name:
    Substitute environment variables referred to in STRING.
    A $ begins a request to substitute; the env variable name is the alphanumeric
    characters and underscores after the $, or is surrounded by braces.
    If a ~ appears following a /, everything through that / is discarded.
    On VMS, $ substitution is not done; this function does little and only
    duplicates what expand-file-name does.

Both of them will expand an initial "~" to your home directory;
substitute-in-file-name will expand $HOME.

Dale

Dale Worley		Compass, Inc.			worley@compass.com
--
The perfect computer has been developed.  You just feed in your problems and
they never come out again.