Files
nixpkgs/pkgs/applications/editors/emacs/build-support/wrapper.sh
Lin Jian 88accc0c92 emacs: use PATH instead of exec-path to expose wrapped binaries
(info "(elisp) Subprocess Creation") says:

> Generally, you should not modify ‘exec-path’ directly.  Instead,
> ensure that your ‘PATH’ environment variable is set appropriately
> before starting Emacs.  Trying to modify ‘exec-path’ independently
> of ‘PATH’ can lead to confusing results.

One example of "confusing results" can be found in envrc[1].

This patch follows that recommendation of Emacs lisp manual.

In addition, we added tests for PATH and exec-path.

[1]: https://github.com/purcell/envrc/issues/9
2026-09-28 00:20:32 +08:00

62 lines
1.7 KiB
Bash
Executable File

#!@bash@
IFS=:
newLoadPath=()
newNativeLoadPath=()
addedNewLoadPath=
addedNewNativeLoadPath=
if [[ -n $EMACSLOADPATH ]]
then
while read -rd: entry
do
if [[ -z $entry && -z $addedNewLoadPath ]]
then
newLoadPath+=(@wrapperSiteLisp@)
addedNewLoadPath=1
fi
newLoadPath+=("$entry")
done <<< "$EMACSLOADPATH:"
else
newLoadPath+=(@wrapperSiteLisp@)
newLoadPath+=("")
fi
# NOTE: Even though we treat EMACSNATIVELOADPATH like EMACSLOADPATH in
# this wrapper, empty elements in EMACSNATIVELOADPATH have no special
# meaning for Emacs. Only non-empty elements in EMACSNATIVELOADPATH
# will be prepended to native-comp-eln-load-path.
# https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/startup.el?id=3685387e609753293c4518be75e77c659c3b2d8d#n599
if [[ -n $EMACSNATIVELOADPATH ]]
then
while read -rd: entry
do
if [[ -z $entry && -z $addedNewNativeLoadPath ]]
then
newNativeLoadPath+=(@wrapperSiteLispNative@)
addedNewNativeLoadPath=1
fi
newNativeLoadPath+=("$entry")
done <<< "$EMACSNATIVELOADPATH:"
else
newNativeLoadPath+=(@wrapperSiteLispNative@)
newNativeLoadPath+=("")
fi
export EMACSLOADPATH="${newLoadPath[*]}"
export emacsWithPackages_siteLisp=@wrapperSiteLisp@
export EMACSNATIVELOADPATH="${newNativeLoadPath[*]}"
export emacsWithPackages_siteLispNative=@wrapperSiteLispNative@
export emacsWithPackages_invocationDirectory=@wrapperInvocationDirectory@
export emacsWithPackages_invocationName=@wrapperInvocationName@
if [[ ${PATH-} != *"@wrapperBinDir@":* ]]
then
export PATH="@wrapperBinDir@${PATH:+:$PATH}"
fi
exec @prog@ "$@"