Open utterances-bot opened 1 year ago
I used your code and work flawlessly, Thank you.
Now on my user-emacs-directory/ts-grammars I have the grammars shared library files available, I've also added the ts-grammars to treesit-extra-load-path:
(add-to-list 'treesit-extra-load-path (expand-file-name "ts-grammars" user-emacs-directory))
but I get, for example loading the rust grammar, Error (use-package): Cannot load tree-sitter-rust
I'm using Emacs 29 compiled with tree-sitter support, and (treesit-available-p) eval as true.
Something is wrong on my config, but my nooby emacs knowledge doesn't help.
Below relevant part of my init.el, with your code added. I'm missing somenthing obviously.... what I'm doing wrong?
Thank you. Luigi
(require 'treesit)
(defun my/tree-sitter-compile-grammar (destination &optional path) "Compile grammar at PATH, and place the resulting shared library in DESTINATION." (interactive "fWhere should we put the shared library? \nfWhat tree-sitter grammar are we compiling? \n") (make-directory destination 'parents)
(let* ((default-directory (expand-file-name "src/" (or path default-directory))) (parser-name (thread-last (expand-file-name "grammar.json" default-directory) (json-read-file) (alist-get 'name))) (emacs-module-url "https://raw.githubusercontent.com/casouri/tree-sitter-module/master/emacs-module.h") (tree-sitter-lang-in-url "https://raw.githubusercontent.com/casouri/tree-sitter-module/master/tree-sitter-lang.in") (needs-cpp-compiler nil)) (message "Compiling grammar at %s" path)
(url-copy-file emacs-module-url "emacs-module.h" :ok-if-already-exists)
(url-copy-file tree-sitter-lang-in-url "tree-sitter-lang.in" :ok-if-already-exists)
(with-temp-buffer
(unless
(zerop
(apply #'call-process
(if (file-exists-p "scanner.cc") "c++" "cc") nil t nil
"parser.c" "-I." "--shared" "-o"
(expand-file-name
(format "libtree-sitter-%s%s" parser-name module-file-suffix)
destination)
(cond ((file-exists-p "scanner.c") '("scanner.c"))
((file-exists-p "scanner.cc") '("scanner.cc")))))
(user-error
"Unable to compile grammar, please file a bug report\n%s"
(buffer-string))))
(message "Completed compilation")))
(add-to-list 'treesit-extra-load-path (expand-file-name "ts-grammars" user-emacs-directory))
(use-package tree-sitter-rust :straight (:host github :repo "tree-sitter/tree-sitter-rust" :post-build (my/tree-sitter-compile-grammar (expand-file-name "ts-grammars" user-emacs-directory))))
(Ab)using straight.el for easy tree-sitter grammar installations! - Ethan Leba
:post-build ftw
https://leba.dev/blog/2022/12/12/(ab)using-straightel-for-easy-tree-sitter-grammar-installations/