diff mbox series

[bug#49946,v2,33/33] gnu: Add emacs-tree-sitter-langs.

Message ID 20210829104608.3103-33-pierre.langlois@gmx.com
State New
Headers show
Series gnu: Add tree-sitter. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Pierre Langlois Aug. 29, 2021, 10:46 a.m. UTC
* gnu/packages/tree-sitter.scm (emacs-tree-sitter-langs): New variable.
---
 gnu/packages/tree-sitter.scm | 80 ++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

--
2.33.0

Comments

Pierre Langlois Aug. 29, 2021, 10:53 a.m. UTC | #1
Pierre Langlois <pierre.langlois@gmx.com> writes:

> * gnu/packages/tree-sitter.scm (emacs-tree-sitter-langs): New variable.
> ---
>  gnu/packages/tree-sitter.scm | 80 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 80 insertions(+)
>
> diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm
> index 0454d75ad4..6bb52b68ac 100644
> --- a/gnu/packages/tree-sitter.scm
> +++ b/gnu/packages/tree-sitter.scm
> @@ -709,3 +709,83 @@ Emacs packages that understand code structurally.  For example:
>  @item More informative indexing for imenu.
>  @end enumerate")
>      (license license:expat)))
> +
> +(define-public emacs-tree-sitter-langs
> +  (package
> +    (name "emacs-tree-sitter-langs")
> +    (version "0.10.3")
> +    (source (origin
> +              (method git-fetch)
> +              (uri (git-reference
> +                    (url "https://github.com/emacs-tree-sitter/tree-sitter-langs")
> +                    (commit version)))
> +              (file-name (git-file-name name version))
> +              (sha256
> +               (base32
> +                "0fa0xi8sky5h3rscnvcci9djdi71qj30vivzzvx7w8pqkmsy1vq7"))))
> +    (build-system emacs-build-system)
> +    ;; FIXME: Support for some languages, such as bash, is still missing from
> +    ;; the bundle.

Whoops, I forgot to update the comment after adding support for bash,
I'll fix that locally!

Thanks,
Pierre
diff mbox series

Patch

diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm
index 0454d75ad4..6bb52b68ac 100644
--- a/gnu/packages/tree-sitter.scm
+++ b/gnu/packages/tree-sitter.scm
@@ -709,3 +709,83 @@  Emacs packages that understand code structurally.  For example:
 @item More informative indexing for imenu.
 @end enumerate")
     (license license:expat)))
+
+(define-public emacs-tree-sitter-langs
+  (package
+    (name "emacs-tree-sitter-langs")
+    (version "0.10.3")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/emacs-tree-sitter/tree-sitter-langs")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0fa0xi8sky5h3rscnvcci9djdi71qj30vivzzvx7w8pqkmsy1vq7"))))
+    (build-system emacs-build-system)
+    ;; FIXME: Support for some languages, such as bash, is still missing from
+    ;; the bundle.
+    (inputs
+     `(("tree-sitter-bash" ,tree-sitter-bash)
+       ("tree-sitter-c" ,tree-sitter-c)
+       ("tree-sitter-cpp" ,tree-sitter-cpp)
+       ("tree-sitter-css" ,tree-sitter-css)
+       ("tree-sitter-go" ,tree-sitter-go)
+       ("tree-sitter-html" ,tree-sitter-html)
+       ("tree-sitter-java" ,tree-sitter-java)
+       ("tree-sitter-javascript" ,tree-sitter-javascript)
+       ("tree-sitter-json" ,tree-sitter-json)
+       ("tree-sitter-julia" ,tree-sitter-julia)
+       ("tree-sitter-php" ,tree-sitter-php)
+       ("tree-sitter-python" ,tree-sitter-python)
+       ("tree-sitter-rust" ,tree-sitter-rust)
+       ("tree-sitter-typescript" ,tree-sitter-typescript)))
+    (propagated-inputs
+     `(("emacs-tree-sitter" ,emacs-tree-sitter)))
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-before 'build 'fake-bundle
+           (lambda _
+             ;; The BUNDLE-VERSION file prevents the package from
+             ;; downloading libraries at load time.
+             (call-with-output-file "bin/BUNDLE-VERSION"
+               (lambda (port) (display ,version port)))))
+         (add-after 'install 'install-libs
+           (lambda* (#:key outputs inputs #:allow-other-keys)
+             (let ((elpa (elpa-directory (assoc-ref outputs "out"))))
+               (define (install-lib lang)
+                 (let ((input (assoc-ref inputs (string-append "tree-sitter-" lang))))
+                   (copy-file (string-append input "/lib/tree-sitter/" lang ".so")
+                              (string-append elpa "/bin/" lang ".so"))))
+               (mkdir-p (string-append elpa "/bin"))
+               ;; The BUNDLE-VERSION file prevents the package from
+               ;; downloading libraries at load time.
+               (call-with-output-file (string-append elpa "/bin/BUNDLE-VERSION")
+                 (lambda (port) (display ,version port)))
+               (for-each (lambda (input)
+                           (use-modules (ice-9 regex))
+                           (cond
+                            ((string-match "^tree-sitter-(.*)$" (car input))
+                             => (lambda (m)
+                                  (install-lib (match:substring m 1))))))
+                         inputs))))
+         (add-after 'install 'install-queries
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((elpa (elpa-directory (assoc-ref outputs "out"))))
+                (copy-recursively "queries" (string-append elpa "/queries"))))))))
+    (home-page "https://ubolonton.github.io/emacs-tree-sitter/languages/")
+    (synopsis "Language support bundle for Tree-sitter")
+    (description "This package is a convenient language bundle for
+Tree-sitter.  For each supported language, this package provides:
+
+@enumerate
+@item Pre-compiled grammar binaries.
+@item An optional highlights.scm file that provides highlighting patterns.
+This is mainly intended for major modes that are not aware of tree-sitter.
+@item Optional query patterns for other minor modes that provide high-level
+functionalities on top of tree-sitter, such as code folding, evil text
+objects, ...etc.
+@end enumerate")
+    (license license:expat)))