about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorChris Hodapp <108633+clhodapp@users.noreply.github.com>2023-03-14 20:51:29 -0700
committerGitHub <noreply@github.com>2023-03-15 16:51:29 +1300
commit1a8edfe192baf0775391ce520092db3c37ff5035 (patch)
tree71c4056f9b67f5b736685a6e11b7c0578452e015 /pkgs/build-support
parent28b44d37a286adeaeeb01acbda8e0b0b80f245ee (diff)
emacs: Add basic tree-sitter support (#219559)
This commit adds basic support for tree-sitter in the emacs build,
such that (if the user opts into tree-sitter support), tree-sitter
will be enabled and binary library files for tree-sitter can be
included in the `lib` directory of packages passed to
`emacsWithPackages`. The libraries will be aggregated and included in
treesit-extra-load-path.

The previous pattern for this in the community was to add tree-sitter
libaries by patching emacs's `RUNPATH` with `patchelf` in a post-fixup
phase. However, this has the substantial drawback that two different
emacs installations with different lists of available tree-sitter
libraries must be entirely separate builds. By supplying the
tree-sitter libraries in the wrapping layer of `emacsWithpackages`, it
becomes possible to share a single, more-cacheable "core emacs".

This support defaults to "on" only in emacs 29 and up, since previous
versions do not support tree-sitter out of the box.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/emacs/wrapper.nix11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix
index edbe3ed971734..3f6a224fa6cd6 100644
--- a/pkgs/build-support/emacs/wrapper.nix
+++ b/pkgs/build-support/emacs/wrapper.nix
@@ -42,6 +42,8 @@ let
 
   nativeComp = emacs.nativeComp or false;
 
+  treeSitter = emacs.treeSitter or false;
+
 in
 
 packagesFun: # packages explicitly requested by the user
@@ -109,6 +111,9 @@ runCommand
         ${optionalString nativeComp ''
           mkdir -p $out/share/emacs/native-lisp
         ''}
+        ${optionalString treeSitter ''
+          mkdir -p $out/lib
+        ''}
 
         local requires
         for pkg in $explicitRequires; do
@@ -133,6 +138,9 @@ runCommand
           ${optionalString nativeComp ''
             linkPath "$1" "share/emacs/native-lisp" "share/emacs/native-lisp"
           ''}
+          ${optionalString treeSitter ''
+            linkPath "$1" "lib" "lib"
+          ''}
         }
 
         # Iterate over the array of inputs (avoiding nix's own interpolation)
@@ -164,6 +172,9 @@ runCommand
         ${optionalString nativeComp ''
           (add-to-list 'native-comp-eln-load-path "$out/share/emacs/native-lisp/")
         ''}
+        ${optionalString treeSitter ''
+          (add-to-list 'treesit-extra-load-path "$out/lib/")
+        ''}
         EOF
 
         # Generate a subdirs.el that statically adds all subdirectories to load-path.