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 https://github.com/NixOS/nixpkgs/pull/106486/commits/23d4bfb6661ca57a9e331a2cf4184232d38ac38b). 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>
This commit is contained in:
co-authored by
Lin Jian
parent
47b7878e2c
commit
5f9cbf9898
@@ -198,6 +198,8 @@ runCommand
|
||||
--subst-var-by bash ${emacs.stdenv.shell} \
|
||||
--subst-var-by wrapperSiteLisp "$deps/share/emacs/site-lisp" \
|
||||
--subst-var-by wrapperSiteLispNative "$deps/share/emacs/native-lisp" \
|
||||
--subst-var-by wrapperInvocationDirectory "$out/bin/" \
|
||||
--subst-var-by wrapperInvocationName "$progname" \
|
||||
--subst-var prog
|
||||
chmod +x $out/bin/$progname
|
||||
# Create a “NOP” binary wrapper for the pure sake of it becoming a
|
||||
@@ -222,6 +224,8 @@ runCommand
|
||||
--subst-var-by bash ${emacs.stdenv.shell} \
|
||||
--subst-var-by wrapperSiteLisp "$deps/share/emacs/site-lisp" \
|
||||
--subst-var-by wrapperSiteLispNative "$deps/share/emacs/native-lisp" \
|
||||
--subst-var-by wrapperInvocationDirectory "$out/Applications/Emacs.app/Contents/MacOS/" \
|
||||
--subst-var-by wrapperInvocationName "Emacs" \
|
||||
--subst-var-by prog "$emacs/Applications/Emacs.app/Contents/MacOS/Emacs"
|
||||
chmod +x $out/Applications/Emacs.app/Contents/MacOS/Emacs
|
||||
wrapProgramBinary $out/Applications/Emacs.app/Contents/MacOS/Emacs
|
||||
|
||||
Regular → Executable
+3
@@ -50,4 +50,7 @@ export emacsWithPackages_siteLisp=@wrapperSiteLisp@
|
||||
export EMACSNATIVELOADPATH="${newNativeLoadPath[*]}"
|
||||
export emacsWithPackages_siteLispNative=@wrapperSiteLispNative@
|
||||
|
||||
export emacsWithPackages_invocationDirectory=@wrapperInvocationDirectory@
|
||||
export emacsWithPackages_invocationName=@wrapperInvocationName@
|
||||
|
||||
exec @prog@ "$@"
|
||||
|
||||
@@ -39,6 +39,16 @@ least specific (the system profile)"
|
||||
(setenv "EMACSNATIVELOADPATH" (when new-env-list
|
||||
(mapconcat 'identity new-env-list ":"))))))
|
||||
|
||||
(let ((wrapper-invocation-directory (getenv "emacsWithPackages_invocationDirectory")))
|
||||
(when wrapper-invocation-directory
|
||||
(setq invocation-directory (file-name-as-directory wrapper-invocation-directory))
|
||||
(setenv "emacsWithPackages_invocationDirectory" nil)))
|
||||
|
||||
(let ((wrapper-invocation-name (getenv "emacsWithPackages_invocationName")))
|
||||
(when wrapper-invocation-name
|
||||
(setq invocation-name wrapper-invocation-name)
|
||||
(setenv "emacsWithPackages_invocationName" nil)))
|
||||
|
||||
;;; Set up native-comp load path.
|
||||
(when (featurep 'native-compile)
|
||||
;; Append native-comp subdirectories from `NIX_PROFILES'.
|
||||
|
||||
Reference in New Issue
Block a user