1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/pkgs/applications/editors/emacs/build-support/wrapper.sh
Alexey Lebedeff 5f9cbf9898
emacs: allow wrapped emacs to execute itself again
fixes #145302 #237855

emacsWithPackages wrapper script/`site-start.el` sanitize
EMACSLOADPATH, to make nested emacs invocations independent of the
package set specified in emacsWithPackages.

But there are valid use cases when one needs to call nested emacs with
the same package set. This includes built-in emacs functionality such
as async native compilations, and also external packages like
`emacs-async` and `esup`. In all of these cases
`invocation-directory`/`invocation-name` variables are being used to
launch nested emacs.

With this patch these variables will be populated to point to the
emacsWithPackages wrapper executable, so that executing
`(file-name-concat invocation-directory invocation-name)` will give a
fully functional emacs again.

`EMACSLOADPATH` sanitization was introduced by #106486, this behaviour
stays unchanged. The reasoning was to be able to run different emacs
executables without polluting their EMACSLOADPATH (as described here
23d4bfb666).
The only change is that invoking itself is again feasible (and that's
what emacs actually expects).

Co-authored-by: Lin Jian <me@linj.tech>
2024-12-06 13:12:47 +08:00

57 lines
1.6 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@
exec @prog@ "$@"