3.7.1 Setting a custom load-path

When installing packages manually, you must make sure its libraries are available on your load-path. See Lisp Libraries in GNU Emacs Manual, for more details about package loading.

The :load-path keyword provides a convenient way to add directories to your load path. It takes as argument a symbol, a function, a string or a list of strings. If a directory is specified as a relative file name, it is expanded relative to user-emacs-directory.

For example:

(use-package org
  :load-path "site-lisp/org/lisp/"
  :commands org-mode)

When using a symbol or a function to provide a dynamically generated list of directories, you must inform the byte-compiler of this definition, so that the value is available at byte-compilation time. This is done by using the special form eval-and-compile (as opposed to eval-when-compile, see Eval During Compile in GNU Emacs Lisp Reference Manual). Furthermore, this value is fixed to the value it had during compilation. If the operation is costly, you do not have to repeat it again on each startup. For example:

(eval-and-compile
  (defun ess-site-load-path ()
    (shell-command-to-string "find ~ -path ess/lisp")))

(use-package ess-site
  :load-path (lambda () (list (ess-site-load-path)))
  :commands R)