From 4489718d8ff8c5f584160113d8482f8546c14804 Mon Sep 17 00:00:00 2001 From: Daniel Nagy Date: Sun, 3 Apr 2022 19:28:23 +0200 Subject: emacsWrapper: preload autoloads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commits changes the Emacs wrapper, in order to preload all autoload definitions when built with additional packages. The list of all definitions is generated at build-time. Packages do not need to be (require)d for them to work. Before this change, a code like ```sh nix-shell -I "nixpkgs=$PWD" -p "emacs.pkgs.withPackages(e:[e.magit])" \ --run "emacs -Q -nw -f magit" ``` will fail with the message `Symbol’s function definition is void: magit` After the change, the same code above will open Emacs with magit enabled. A slightly longer startup time of ~10ms was detected in local, informal experiments. More information on autoloading: https://www.gnu.org/software/emacs/manual/html_node/eintr/Autoload.html --- pkgs/build-support/emacs/wrapper.nix | 9 +++++++-- pkgs/build-support/emacs/wrapper.sh | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'pkgs/build-support/emacs') diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix index 2aa61d6d2f62f..207908fb606fb 100644 --- a/pkgs/build-support/emacs/wrapper.nix +++ b/pkgs/build-support/emacs/wrapper.nix @@ -135,9 +135,14 @@ 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 siteStart="$out/share/emacs/site-lisp/site-start.el" @@ -174,12 +179,12 @@ runCommand > "$subdirs" # Byte-compiling improves start-up time only slightly, but costs nothing. - $emacs/bin/emacs --batch -f batch-byte-compile "$siteStart" "$subdirs" + $emacs/bin/emacs --batch -f batch-byte-compile "$siteStart" "$subdirs" "$siteAutoloads" ${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" + -f batch-native-compile "$siteStart" "$subdirs" "$siteAutoloads" ''} ''; diff --git a/pkgs/build-support/emacs/wrapper.sh b/pkgs/build-support/emacs/wrapper.sh index e8eecb8c86966..6c5a5aee2a8f6 100644 --- a/pkgs/build-support/emacs/wrapper.sh +++ b/pkgs/build-support/emacs/wrapper.sh @@ -44,4 +44,4 @@ export emacsWithPackages_siteLisp=@wrapperSiteLisp@ export EMACSNATIVELOADPATH="${newNativeLoadPath[*]}" export emacsWithPackages_siteLispNative=@wrapperSiteLispNative@ -exec @prog@ "$@" +exec @prog@ -l cl-loaddefs -l nix-generated-autoload "$@" -- cgit 1.4.1