guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#49946] [PATCH v5 27/27] gnu: Add emacs-tree-sitter-langs.


From: Pierre Langlois
Subject: [bug#49946] [PATCH v5 27/27] gnu: Add emacs-tree-sitter-langs.
Date: Tue, 29 Mar 2022 20:43:18 +0100

* gnu/packages/tree-sitter.scm (make-emacs-tree-sitter-langs-grammar-bundle):
New procedure.
(emacs-tree-sitter-langs): New variable.
---
 gnu/packages/tree-sitter.scm | 137 +++++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)

diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm
index 97a20494ec..ae0478c3e4 100644
--- a/gnu/packages/tree-sitter.scm
+++ b/gnu/packages/tree-sitter.scm
@@ -24,6 +24,7 @@ (define-module (gnu packages tree-sitter)
   #:use-module (guix build-system emacs)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system tree-sitter)
+  #:use-module (guix build-system trivial)
   #:use-module (guix download)
   #:use-module (guix git-download)
   #:use-module (guix packages)
@@ -793,3 +794,139 @@ (define-public emacs-tree-sitter
 @item More informative indexing for imenu.
 @end enumerate")
     (license license:expat)))
+
+(define (make-emacs-tree-sitter-langs-grammar-bundle version)
+  (package
+    (name "emacs-tree-sitter-langs-grammar-bundle")
+    (source #f)
+    (version version)
+    (build-system trivial-build-system)
+    (inputs
+     ;; FIXME: Support for some languages is still left to package.
+     (list tree-sitter-bash
+           tree-sitter-c
+           tree-sitter-c-sharp
+           tree-sitter-cpp
+           tree-sitter-css
+           tree-sitter-elixir
+           tree-sitter-elm
+           tree-sitter-go
+           tree-sitter-html
+           tree-sitter-java
+           tree-sitter-javascript
+           tree-sitter-json
+           tree-sitter-julia
+           tree-sitter-ocaml
+           tree-sitter-php
+           tree-sitter-python
+           tree-sitter-rust
+           tree-sitter-ruby
+           tree-sitter-typescript))
+    (arguments
+     (list #:builder
+           (with-imported-modules '((guix build union)
+                                    (guix build utils))
+             #~(begin
+                 (use-modules (ice-9 match)
+                              (guix build union)
+                              (guix build utils))
+                 (union-build
+                  #$output
+                  (filter directory-exists?
+                          (map (match-lambda
+                                 ((name directory)
+                                  (string-append directory 
"/lib/tree-sitter")))
+                               '#$(package-inputs this-package))))
+                  ;; The BUNDLE-VERSION file prevents emacs-tree-sitter-langs
+                  ;; from downloading libraries at load time.
+                  (call-with-output-file (string-append #$output 
"/BUNDLE-VERSION")
+                    (lambda (port) (display #$version port)))))))
+    (synopsis #f)
+    (description #f)
+    (home-page #f)
+    (license #f)))
+
+(define-public emacs-tree-sitter-langs
+  (package
+    (name "emacs-tree-sitter-langs")
+    (version "0.11.6")
+    (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
+                "0jyzpiyl3b88vwfzkda7ak77kl0b2nybvsz0j9cndl3pf95d62g0"))))
+    (build-system emacs-build-system)
+    (inputs
+     (list (make-emacs-tree-sitter-langs-grammar-bundle version)))
+    (propagated-inputs
+     (list emacs-tree-sitter))
+    (arguments
+     (list
+      #:tests? #t
+      #:test-command ''("script/test")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'remove-cask
+            (lambda _
+              (substitute* "script/test"
+                (("cask") ""))))
+          (add-before 'check 'bundle-for-testing
+            (lambda* (#:key inputs #:allow-other-keys)
+              (delete-file-recursively "bin")
+              (symlink #$(make-emacs-tree-sitter-langs-grammar-bundle version)
+                       "bin")))
+          (add-before 'check 'patch-tree-sitter-require-test
+            (lambda _
+              (use-modules (ice-9 regex))
+              ;; This test needs a git repositories with submodules for
+              ;; each languages in order to map all repositories.  We patch
+              ;; the mapping function with one that invokes the tests for each
+              ;; packaged language.
+              (let ((supported-languages
+                     (map (lambda (lib)
+                            (match:substring
+                             (string-match "(.*)\\.so$" (basename lib))
+                             1))
+                          (find-files "bin" "\\.so$"))))
+                (substitute* "tree-sitter-langs-tests.el"
+                  (("tree-sitter-langs--map-repos")
+                   (call-with-output-string
+                     (lambda (port)
+                       (write `(lambda (fn)
+                                 (dolist (lang ',supported-languages)
+                                         (funcall fn lang)))
+                              port))))))))
+          ;; Tests for queries will fail given those languages are not
+          ;; packages yet.
+          (add-before 'check 'remove-unused-highlight-queries
+            (lambda _
+              (delete-file-recursively "queries/hcl")
+              (delete-file-recursively "queries/pgn")))
+          (add-before 'install 'install-bundle
+            (lambda _
+              (let ((elpa (elpa-directory #$output)))
+                (mkdir-p elpa)
+                (symlink #$(make-emacs-tree-sitter-langs-grammar-bundle 
version)
+                         (string-append elpa "/bin")))))
+          (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)))
--
2.34.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]