GNU bug report logs - #49946
[PATCH 00/31] Tree-sitter, node-gyp addon support and emacs-tree-sitter

Previous Next

Package: guix-patches;

Reported by: Pierre Langlois <pierre.langlois <at> gmx.com>

Date: Sun, 8 Aug 2021 23:27:01 UTC

Severity: normal

Tags: patch

Full log


Message #854 received at 49946 <at> debbugs.gnu.org (full text, mbox):

From: Luis Henrique Gomes Higino <luishenriquegh2701 <at> gmail.com>
To: 49946 <at> debbugs.gnu.org, Pierre Langlois <pierre.langlois <at> gmx.com>
Subject: Re: About migrating support from emacs-tree-sitter to treesit
Date: Sun, 29 Jan 2023 20:10:18 -0300
[Message part 1 (text/plain, inline)]
Hi guix,

Luis Henrique Gomes Higino <luishenriquegh2701 <at> gmail.com> writes:

> Hi guix,
>
> I was taking a look at this patch series again and wondering if 
> it
> could
> be modified to support the new built in treesit module coming in
> Emacs 29 instead of emacs-tree-sitter, as the latter recommends 
> using
> the native integration going forward [1]. Maybe we should leave 
> this
> to when
> Emacs 29 is released, but I think working on this in advance 
> could
> result on it being delivered earlier, which would be great. What 
> do
> you think Pierre?
>
> [1]:
> https://github.com/emacs-tree-sitter/elisp-tree-sitter/commit/d3eab879e9b0ccc9582113d81a93ad06f3c6bfb1
>
> PS: I'm willing to help
>
> Regards,

I played around this idea this weekend and I got `treesit' to use 
the Guix installed grammars :) !

First, I applied a patch that added tree-sitter as an input for 
emacs-next [1]. 

[1]: https://issues.guix.gnu.org/61139

Then, I did the edits below on top of Pierre's latest patch 
series:

[0001-Support-treesit-module-from-emacs.patch (text/plain, inline)]
From fb96ca9c6039d07856c8f3525919ed9036b39470 Mon Sep 17 00:00:00 2001
From: Luis Henrique Gomes Higino <luishenriquegh2701 <at> gmail.com>
Date: Sun, 29 Jan 2023 20:24:04 -0300
Subject: [PATCH] Support treesit module from emacs

---
 gnu/packages/emacs.scm                  | 8 +++++++-
 guix/build/tree-sitter-build-system.scm | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 951c1ad6df..193547ff42 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -409,7 +409,13 @@ (define-public emacs-next
          (prepend sqlite tree-sitter)))
       (native-inputs
        (modify-inputs (package-native-inputs emacs)
-         (prepend autoconf))))))
+         (prepend autoconf)))
+      (native-search-paths
+       (cons
+        (search-path-specification
+         (variable "TREE_SITTER_GRAMMARS")
+         (files '("lib/tree-sitter")))
+        (package-native-search-paths emacs))))))
 
 (define-public emacs-next-pgtk
   (package
diff --git a/guix/build/tree-sitter-build-system.scm b/guix/build/tree-sitter-build-system.scm
index 574b0f2a1c..ee1aa9976c 100644
--- a/guix/build/tree-sitter-build-system.scm
+++ b/guix/build/tree-sitter-build-system.scm
@@ -114,7 +114,7 @@ (define (compile-language dir)
                    "-fno-exceptions"
                    "-O2"
                    "-g"
-                   "-o" ,(string-append lib "/" lang ".so")
+                   "-o" ,(string-append lib "/libtree-sitter-" lang ".so")
                    ;; An additional `scanner.{c,cc}' file is sometimes
                    ;; provided.
                    ,@(cond
-- 
2.39.1

[Message part 3 (text/plain, inline)]
Then, I ran `./pre-inst-env guix shell emacs-next tree-sitter-c 
tree-sitter-cpp --container --preserve="^TERM$" -- emacs -Q -nw` 
and executed the following code inside that Emacs session:

--8<---------------cut here---------------start------------->8---
(defvar guix-treesit-grammar-paths
 (let ((grammars-path (if (getenv "TREE_SITTER_GRAMMARS")
                          (getenv "TREE_SITTER_GRAMMARS")
                        "")))
   (split-string grammars-path ":")))

(if (treesit-available-p)
   (setq treesit-extra-load-path guix-treesit-grammar-paths))
--8<---------------cut here---------------end--------------->8---

Doing these steps, Emacs' treesit was able to use the grammars 
installed by Guix in c-ts-mode. I don't know if a native 
search-path is the appropriate approach or how to include the 
above elisp (or something similar) in the emacs-next package, but 
I hope this helps Pierre or anyone else with more understanding to 
do the v8 of this patch series :).

Regards,
-- 
Luis H. Higino

This bug report was last modified 2 years and 119 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.