6 , plugins ? map (g: tree-sitter-grammars.${g}) (lib.importJSON ./default-grammars.json)
11 inherit (melpaStablePackages) tree-sitter-langs;
13 langName = g: lib.removeSuffix "-grammar" (lib.removePrefix "tree-sitter-" g.pname);
14 soName = g: langName g + stdenv.hostPlatform.extensions.sharedLibrary;
16 grammarDir = runCommand "emacs-tree-sitter-grammars" {
17 # Fake same version number as upstream language bundle to prevent triggering runtime downloads
18 inherit (tree-sitter-langs) version;
20 install -d $out/langs/bin
21 echo -n $version > $out/langs/bin/BUNDLE-VERSION
22 '' + lib.concatStringsSep "\n" (map (
23 g: "ln -s ${g}/parser $out/langs/bin/${soName g}") plugins
25 siteDir = "$out/share/emacs/site-lisp/elpa/${tree-sitter-langs.pname}-${tree-sitter-langs.version}";
28 melpaStablePackages.tree-sitter-langs.overrideAttrs(old: {
29 postPatch = old.postPatch or "" + ''
30 substituteInPlace ./tree-sitter-langs-build.el \
31 --replace "tree-sitter-langs-grammar-dir tree-sitter-langs--dir" "tree-sitter-langs-grammar-dir \"${grammarDir}/langs\""
36 + lib.concatStringsSep "\n"
39 if [[ -d "${g}/queries" ]]; then
40 mkdir -p ${siteDir}/queries/${langName g}/
41 for f in ${g}/queries/*; do
42 ln -sfn "$f" ${siteDir}/queries/${langName g}/
47 passthru = old.passthru or {} // {
49 withPlugins = fn: final.tree-sitter-langs.override { plugins = fn tree-sitter-grammars; };