fix emacs-tree-sitter

This commit is contained in:
Tim Schubert 2021-08-05 22:13:53 +02:00
parent 9822045da5
commit 1b0c4b3924
Signed by: dadada
GPG key ID: EEB8D1CE62C4DFEA
5 changed files with 149 additions and 46 deletions

View file

@ -13,10 +13,58 @@ in
programs.doom-emacs = {
enable = true;
doomPrivateDir = ./doom.d;
emacsPackagesOverlay = self: super: with pkgs; {
tsc = super.tsc.overrideAttrs (old:
let
libtsc_dyn = rustPlatform.buildRustPackage rec {
pname = "emacs-tree-sitter";
version = "0.15.1";
src = fetchFromGitHub {
owner = "ubolonton";
repo = "emacs-tree-sitter";
rev = version;
sha256 = "sha256-WgkGtmw63+kRLTRiSEO4bFF2IguH5g4odCujyazkwJc=";
};
preBuild = ''
export BINDGEN_EXTRA_CLANG_ARGS="$(< ${stdenv.cc}/nix-support/libc-crt1-cflags) \
$(< ${stdenv.cc}/nix-support/libc-cflags) \
$(< ${stdenv.cc}/nix-support/cc-cflags) \
$(< ${stdenv.cc}/nix-support/libcxx-cxxflags) \
${lib.optionalString stdenv.cc.isClang "-idirafter ${stdenv.cc.cc}/lib/clang/${lib.getVersion stdenv.cc.cc}/include"} \
${lib.optionalString stdenv.cc.isGNU
"-isystem ${stdenv.cc.cc}/lib/gcc/${stdenv.hostPlatform.config}/${lib.getVersion stdenv.cc.cc}/include/"} \
${lib.optionalString stdenv.cc.isGNU
"-isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc} -isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc}/${stdenv.hostPlatform.config}"} \
$NIX_CFLAGS_COMPILE"
'';
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
cargoHash = "sha256-HB5tFR1slY2D6jb2mt4KrGrGBUUVrxiBjmVycO+qfYY=";
};
in
{
inherit (libtsc_dyn) src;
preBuild = ''
ext=${stdenv.hostPlatform.extensions.sharedLibrary}
dest=$out/share/emacs/site-lisp/elpa/tsc-${old.version}
install -D ${libtsc_dyn}/lib/libtsc_dyn$ext $dest/tsc-dyn$ext
echo -n "0.15.1" > $dest/DYN-VERSION
'';
});
tree-sitter-langs = super.tree-sitter-langs.overrideAttrs (old: {
postInstall = ''
dest=$out/share/emacs/site-lisp/elpa/tree-sitter-langs-${old.version}
echo -n "0.10.2" > $dest/BUNDLE-VERSION
${lib.concatStringsSep "\n"
(lib.mapAttrsToList (name: src: "name=${name}; ln -s ${src}/parser $dest/bin/\${name#tree-sitter-}.so") pkgs.tree-sitter.builtGrammars)};
'';
});
};
};
services.emacs = {
enable = true;
socketActivation.enable = true;
};
home.file.".tree-sitter".source = (pkgs.runCommand "grammars" {} ''
mkdir -p $out/bin
echo -n "0.10.2" > $out/BUNDLE-VERSION
${lib.concatStringsSep "\n"
(lib.mapAttrsToList (name: src: "name=${name}; ln -s ${src}/parser $out/bin/\${name#tree-sitter-}.so") pkgs.tree-sitter.builtGrammars)};
'');
};
}

View file

@ -2,8 +2,11 @@
(setq org-directory "~/src/notes/org/")
(with-eval-after-load 'treemacs
(define-key treemacs-mode-map [mouse-1] #'treemacs-single-click-expand-action))
(defun fixed-tree-sitter-langs-install-grammars (&optional skip-if-installed version os keep-bundle) ())
(advice-add 'tree-sitter-langs-install-grammars :override #'fixed-tree-sitter-langs-install-grammars)
(use-package! tree-sitter
:config
(cl-pushnew (expand-file-name "~/.tree-sitter") tree-sitter-load-path)
(require 'tree-sitter-langs)
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))

View file

@ -1,2 +1,3 @@
(package! direnv)
(package! tree-sitter)
(package! tree-sitter-langs)