about summary refs log tree commit diff
path: root/pkgs/build-support/emacs/setup-hook.sh
blob: 8f074e0b406c6fc53df4b43373417a23167d5473 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
addEmacsVars () {
  for lispDir in \
      "$1/share/emacs/site-lisp" \
      "$1/share/emacs/site-lisp/"* \
      "$1/share/emacs/site-lisp/elpa/"*; do
    # Add the path to the Emacs load path if it is a directory
    # containing .el files and it has not already been added to the
    # load path.
    if [[ -d $lispDir && "$(echo "$lispDir"/*.el)" && ${EMACSLOADPATH-} != *"$lispDir":* ]] ; then
      # It turns out, that the trailing : is actually required
      # see https://www.gnu.org/software/emacs/manual/html_node/elisp/Library-Search.html
      export EMACSLOADPATH="$lispDir:${EMACSLOADPATH-}"
    fi
  done
}

if [[ ! -v emacsHookDone ]]; then
  emacsHookDone=1

  # If this is for a wrapper derivation, emacs and the dependencies are all
  # run-time dependencies. If this is for precompiling packages into bytecode,
  # emacs is a compile-time dependency of the package.
  addEnvHooks "$hostOffset" addEmacsVars
  addEnvHooks "$targetOffset" addEmacsVars
fi