about summary refs log tree commit diff
path: root/pkgs/applications/editors/emacs
diff options
context:
space:
mode:
authortalyz <kim.lindberger@gmail.com>2022-08-25 18:40:41 +0200
committertalyz <kim.lindberger@gmail.com>2022-08-25 18:40:41 +0200
commitfaee7f1311c5dfc2aa80c29ac2558e9f6a4ba792 (patch)
tree6ff854a89e71f5398547169b71d1c3bd6f87f944 /pkgs/applications/editors/emacs
parent784686d06c62639c8b5ef6e78524b0d74db85433 (diff)
downloadnixlib-faee7f1311c5dfc2aa80c29ac2558e9f6a4ba792.tar
nixlib-faee7f1311c5dfc2aa80c29ac2558e9f6a4ba792.tar.gz
nixlib-faee7f1311c5dfc2aa80c29ac2558e9f6a4ba792.tar.bz2
nixlib-faee7f1311c5dfc2aa80c29ac2558e9f6a4ba792.tar.lz
nixlib-faee7f1311c5dfc2aa80c29ac2558e9f6a4ba792.tar.xz
nixlib-faee7f1311c5dfc2aa80c29ac2558e9f6a4ba792.tar.zst
nixlib-faee7f1311c5dfc2aa80c29ac2558e9f6a4ba792.zip
emacs.pkgs.tree-sitter-langs: Link to each grammar's query files
Create symlinks to the query files provided by the grammars. This
makes syntax highlighting works properly for languages which
tree-sitter-langs doesn't provide query files and updates the ones it
provides to the latest upstream files.
Diffstat (limited to 'pkgs/applications/editors/emacs')
-rw-r--r--pkgs/applications/editors/emacs/elisp-packages/tree-sitter-langs/default.nix17
1 files changed, 16 insertions, 1 deletions
diff --git a/pkgs/applications/editors/emacs/elisp-packages/tree-sitter-langs/default.nix b/pkgs/applications/editors/emacs/elisp-packages/tree-sitter-langs/default.nix
index e62a37565c83..cb4cec172bac 100644
--- a/pkgs/applications/editors/emacs/elisp-packages/tree-sitter-langs/default.nix
+++ b/pkgs/applications/editors/emacs/elisp-packages/tree-sitter-langs/default.nix
@@ -17,7 +17,8 @@ let
   inherit (melpaStablePackages) tree-sitter-langs;
 
   libSuffix = if stdenv.isDarwin then "dylib" else "so";
-  soName = g: lib.removeSuffix "-grammar" (lib.removePrefix "tree-sitter-" g.pname) + "." + libSuffix;
+  langName = g: lib.removeSuffix "-grammar" (lib.removePrefix "tree-sitter-" g.pname);
+  soName = g: langName g + "." + libSuffix;
 
   grammarDir = runCommand "emacs-tree-sitter-grammars" {
     # Fake same version number as upstream language bundle to prevent triggering runtime downloads
@@ -28,6 +29,7 @@ let
   '' + lib.concatStringsSep "\n" (map (
     g: "ln -s ${g}/parser $out/langs/bin/${soName g}") plugins
   ));
+  siteDir = "$out/share/emacs/site-lisp/elpa/${tree-sitter-langs.pname}-${tree-sitter-langs.version}";
 
 in
 melpaStablePackages.tree-sitter-langs.overrideAttrs(old: {
@@ -36,6 +38,19 @@ melpaStablePackages.tree-sitter-langs.overrideAttrs(old: {
     --replace "tree-sitter-langs-grammar-dir tree-sitter-langs--dir"  "tree-sitter-langs-grammar-dir \"${grammarDir}/langs\""
   '';
 
+  postInstall =
+    old.postInstall or ""
+    + lib.concatStringsSep "\n"
+      (map
+        (g: ''
+          if [[ -d "${g}/queries" ]]; then
+            mkdir -p ${siteDir}/queries/${langName g}/
+            for f in ${g}/queries/*; do
+              ln -sfn "$f" ${siteDir}/queries/${langName g}/
+            done
+          fi
+        '') plugins);
+
   passthru = old.passthru or {} // {
     inherit plugins;
     withPlugins = fn: final.tree-sitter-langs.override { plugins = fn tree-sitter-grammars; };