emacsWithPackages: Rely on package.el for autoloads

The builtin `package.el` functionality is necessary and sufficient to handle
autoloads in the Emacs wrapper.
This commit is contained in:
Thomas Tuegel 2022-07-11 20:22:20 -05:00
parent d632b9657c
commit 017fa2d7a0
No known key found for this signature in database
GPG Key ID: 22CBF5249D4B4D59
2 changed files with 3 additions and 16 deletions

View File

@ -135,16 +135,10 @@ runCommand
''}
}
siteAutoloads="$out/share/emacs/site-lisp/nix-generated-autoload.el"
touch $siteAutoloads
# Iterate over the array of inputs (avoiding nix's own interpolation)
for pkg in "''${requires[@]}"; do
linkEmacsPackage $pkg
find $pkg -name "*-autoloads.el" \
-exec echo \(load \"{}\" \'noerror \'nomessage\) \; >> $siteAutoloads
done
echo "(provide 'nix-generated-autoload)" >> $siteAutoloads
siteStart="$out/share/emacs/site-lisp/site-start.el"
siteStartByteCompiled="$siteStart"c
@ -180,12 +174,12 @@ runCommand
> "$subdirs"
# Byte-compiling improves start-up time only slightly, but costs nothing.
$emacs/bin/emacs --batch -f batch-byte-compile "$siteStart" "$subdirs" "$siteAutoloads"
$emacs/bin/emacs --batch -f batch-byte-compile "$siteStart" "$subdirs"
${optionalString nativeComp ''
$emacs/bin/emacs --batch \
--eval "(add-to-list 'native-comp-eln-load-path \"$out/share/emacs/native-lisp/\")" \
-f batch-native-compile "$siteStart" "$subdirs" "$siteAutoloads"
-f batch-native-compile "$siteStart" "$subdirs"
''}
'';
@ -197,18 +191,12 @@ runCommand
# Wrap emacs and friends so they find our site-start.el before the original.
for prog in $emacs/bin/*; do # */
local progname=$(basename "$prog")
local autoloadExpression=""
rm -f "$out/bin/$progname"
if [[ $progname == emacs ]]; then
# progs other than "emacs" do not understand the `-l` switches
autoloadExpression="-l cl-loaddefs -l nix-generated-autoload"
fi
substitute ${./wrapper.sh} $out/bin/$progname \
--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 autoloadExpression \
--subst-var prog
chmod +x $out/bin/$progname
done
@ -228,7 +216,6 @@ 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 autoloadExpression "-l cl-loaddefs -l nix-generated-autoload" \
--subst-var-by prog "$emacs/Applications/Emacs.app/Contents/MacOS/Emacs"
chmod +x $out/Applications/Emacs.app/Contents/MacOS/Emacs
fi

View File

@ -44,4 +44,4 @@ export emacsWithPackages_siteLisp=@wrapperSiteLisp@
export EMACSNATIVELOADPATH="${newNativeLoadPath[*]}"
export emacsWithPackages_siteLispNative=@wrapperSiteLispNative@
exec @prog@ @autoloadExpression@ "$@"
exec @prog@ "$@"