1

I set the environment variable EMACSLOADPATH to change Emacs load-path this way:

mkdir ~/.emacs.d/site-lisp/

export EMACSLOADPATH="$(
  emacs      \
  -Q --batch \
  --eval '(princ user-emacs-directory)'
)"/site-lisp/:

# Let's say there is a teeest library:
echo "(provide 'teeest)" \
  > ~/.emacs.d/site-lisp/teeest.el

Then ran Emacs

emacs -Q --batch

got stderr:

Warning: Lisp directory '~/.emacs.d/site-lisp': No such file or directory

Why does Emacs complain?


Actually, require does know that directory:

emacs                                \
  -Q --batch                         \
  --eval "(princ (require 'teeest))" \
2> /dev/null ; echo

outputs:

teeest
9
  • 1
    Do not quote the RHS of the export. That will allow the shell to expand it properly.
    – NickD
    Commented Aug 27, 2023 at 18:51
  • @NickD: Yeah. But sometimes I must quote it (for some strange reason). ||| Posting this question is intended to remind others not to use ~ in EMACSLOADPATH. Someone will encounter this problem at some time, and he/she probably does not know the reason why Emacs complains. The existence of this question may help.
    – shynur
    Commented Aug 27, 2023 at 20:12
  • If you need to quote something, then quote that something but leave the tilde alone. E.g. if you have a directory foo* under your home directory, do export EMACSLOADPATH=~/foo"*". I fail to see why you think EMACSLOADPATH is somehow special or what this has to do with Emacs. The only parsing that Emacs (or any other program) does on a PATH-like environment variable is to split it at colons and construct a list - that's all.
    – NickD
    Commented Aug 27, 2023 at 23:04
  • @NickD: Sometimes you don't know whether there is a tilde in the string, eg USER_EMACS_SITE_LISP="$(emacs -Q --batch --eval '(princ user-emacs-directory)')/site-lisp/" (this string may also contain whitespaces). A more realistic case: github.com/shynur/.emacs.d/blob/main/etc/use-emacs.bash
    – shynur
    Commented Aug 28, 2023 at 4:36
  • 1
    On rereading everything, the answer is fine: it's the question that is problematic IMO, because you have "simplified" it too much. The answer to the question as it stands is in my first comment above - there is no need for anything else. But your actual question is different and it explicitly involves the fact that user-emacs-directory is a string containing a tilde. That appeared in the answer, but not in the question.
    – NickD
    Commented Aug 28, 2023 at 12:09

1 Answer 1

2

Not sure whether it is an intended behavior - Emacs doesn't recognize ~ in EMACSLOADPATH, though require does recognize it.

One workaround is to expand the pathname:

export EMACSLOADPATH="$(
  emacs      \
  -Q --batch \
  --eval '(princ (file-truename user-emacs-directory))'
)"/site-lisp:

Update:

After @NickD's patient guidance, I'm inclined to believe that users should not expect Emacs to interpret the shorthand representing the HOME directory in EMACSLOADPATH. As some file systems allow filenames to start with a ~.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.