From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4BA4Nld172PBQwEAbAwnHQ (envelope-from ) for ; Fri, 17 Feb 2023 13:38:47 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 4CoKNld172MdjgAAauVa8A (envelope-from ) for ; Fri, 17 Feb 2023 13:38:47 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 662BE1051A for ; Fri, 17 Feb 2023 13:38:47 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pT009-0003nu-L8; Fri, 17 Feb 2023 07:38:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pT004-0003hI-Or for guix-patches@gnu.org; Fri, 17 Feb 2023 07:38:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pT004-000105-Ep for guix-patches@gnu.org; Fri, 17 Feb 2023 07:38:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pT004-0001Ii-Az for guix-patches@gnu.org; Fri, 17 Feb 2023 07:38:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [PATCH v8 7/7] gnu: Add emacs-tree-sitter-langs. Resent-From: Pierre Langlois Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 17 Feb 2023 12:38:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49946 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49946@debbugs.gnu.org Cc: Pierre Langlois Received: via spool by 49946-submit@debbugs.gnu.org id=B49946.16766374614908 (code B ref 49946); Fri, 17 Feb 2023 12:38:04 +0000 Received: (at 49946) by debbugs.gnu.org; 17 Feb 2023 12:37:41 +0000 Received: from localhost ([127.0.0.1]:38709 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSzzh-0001H0-2j for submit@debbugs.gnu.org; Fri, 17 Feb 2023 07:37:41 -0500 Received: from mout.gmx.net ([212.227.17.21]:50655) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSzzX-0001FK-UX for 49946@debbugs.gnu.org; Fri, 17 Feb 2023 07:37:34 -0500 Received: from localhost.localdomain ([82.69.64.142]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MeCpb-1os0kD0pa3-00bGVB; Fri, 17 Feb 2023 13:37:26 +0100 From: Pierre Langlois Date: Fri, 17 Feb 2023 12:37:22 +0000 Message-Id: <20230217123722.15143-8-pierre.langlois@gmx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217123722.15143-1-pierre.langlois@gmx.com> References: <20221125012142.22579-1-pierre.langlois@gmx.com> <20230217123722.15143-1-pierre.langlois@gmx.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:G0NcS7HdWVB6sCgWjA2ktAQQk4cGynOHi9kPpnZyajGzByKiMp4 avHDpiMYYlbdaSb0Cv/KrWWPxUNMb/jDcXUoFTJYNHlv7w8YxA0tppORoPbF+Ev0i5t4vjC eZztwhk6FETcoNfA/76mx8ks+QSi7o9FH/6LPlyxd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+8y34CWZLeyWA= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676637527; a=rsa-sha256; cv=none; b=Z5ciRlk7X6aZynUMctC2FNx2dpVw1SeGRCAoV5F7fUo0cS98v+7UDHPnUMlYId57VF+OP4 t4BcJZPziQR2CkndlIKrWeiwqPtzX5dYDnfwqsBtDAD2FHiQEeN75QWCrIyOSOdLabZRBA 3RHroHwyVL8LPz6I3aXnDfGxll1ax2A7TepDcI/ZkNh/DtkXTcZrQotzi0sKDMUrPipEzG Pa9pVDmZZHMRqF2a5ghWs69FpQIxQ2QYQ6sUFJjVZx+EOA5I3LJ5t40aBQGsVeIpQ0zCQV VS1xrjmVwB6FuwW2919xCO7FjS7ty26RYJwXBZflq4cDEHRLgDSwUoGyI5g6dA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676637527; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=mO93/Jfs+Y5oPox/8MfOPYHJDprp2ROpIP7bcpO8sDY=; b=qvpXMcxNN9WB727gEgK4BXpNJngYOcE9PsEJ49NSG8HMG56QL/Lcpwn+VlTCtrV972bo0M gdDR6nbIudpM9sfNl5lHBdSMdLU1t+KBsAGQoZ2dW3pJWmBDGdyPXthzgzfxO5CnXDtV7k kMpv5BYVnoBUHhViVip0dtNM13NE30Ca4JXEUPFnR+oYeQAJyM7rAVfYM64Hrts+aGpL1u qXWxrnwa60wKT5Yqswg2fr2mw/S+26aDrW60Y9/l1ZE3yiMHYmGXB+ChxdbeI8An4TXyda /N2zSq3bi9L3HHPFRss2h62JRLuIB6qWUPTnyNEkytChEe6uwXfPGQ45fvKSzQ== X-Migadu-Spam-Score: -1.63 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 662BE1051A X-Migadu-Scanner: scn1.migadu.com X-Spam-Score: -1.63 X-TUID: qA9jc+ZRPJTn * gnu/packages/tree-sitter.scm (emacs-tree-sitter-langs-grammar-bundle): New variable. (emacs-tree-sitter-langs): New variable. --- gnu/packages/tree-sitter.scm | 200 +++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm index f8be967e21..2a05179bb4 100644 --- a/gnu/packages/tree-sitter.scm +++ b/gnu/packages/tree-sitter.scm @@ -32,6 +32,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 gexp) #:use-module (guix git-download) @@ -651,3 +652,202 @@ (define-public emacs-tree-sitter @item More informative indexing for imenu. @end enumerate") (license license:expat))) + +;; tree-sitter-langs expects all supported grammars to be bundled in a single +;; directory. Doing this statically also allows us to check that grammars are +;; compatible. +(define emacs-tree-sitter-langs-grammar-bundle + (package + (name "emacs-tree-sitter-langs-grammar-bundle") + (source #f) + (version (package-version tree-sitter)) + (build-system trivial-build-system) + (inputs + ;; When adding support for new languages, also add their names into the + ;; list in the package emacs-tree-sitter-langs package description. + ;; 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-clojure + tree-sitter-css + tree-sitter-elixir + tree-sitter-elm + tree-sitter-go + tree-sitter-haskell + tree-sitter-html + tree-sitter-java + tree-sitter-javascript + tree-sitter-json + tree-sitter-julia + tree-sitter-lua + tree-sitter-markdown-gfm + tree-sitter-ocaml + tree-sitter-php + tree-sitter-python + tree-sitter-r + tree-sitter-ruby + tree-sitter-rust-0.20.2 + tree-sitter-typescript)) + (arguments + (list + #:builder + (with-imported-modules '((guix build union) + (guix build utils)) + #~(begin + (use-modules (ice-9 match) + (srfi srfi-1) + (guix build union) + (guix build utils)) + (mkdir-p #$output) + (for-each + (lambda (lib) + ;; tree-sitter-langs expects grammars to be as ".so" + ;; rather than "libtree-sitter-.so". + (symlink lib + (string-append + #$output + "/" + (substring (basename lib) + (string-length "libtree-sitter-"))))) + (append-map (match-lambda + ((name directory) + (find-files directory "libtree-sitter-.*\\.so$"))) + '#$(package-inputs this-package))))))) + (synopsis #f) + (description #f) + (home-page #f) + (license #f))) + +(define-public emacs-tree-sitter-langs + (package + (name "emacs-tree-sitter-langs") + (version "0.12.16") + (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 + "1i8lhv404ijj52jjxrmljnrhby9jlrdgpymn2jfs4kml0x7qhsna")))) + (build-system emacs-build-system) + (inputs + (list emacs-tree-sitter-langs-grammar-bundle)) + (propagated-inputs + (list emacs-tree-sitter)) + (arguments + (list + #:tests? #t + #:test-command ''("script/test") + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'disable-downloader + (lambda _ + (call-with-output-file "tree-sitter-langs-build.el" + (lambda (port) + (let ((on-load-message + (string-append + "tree-sitter-langs: Grammar bundle already installed " + "via Guix. Installing external grammars via this " + "function isn't supported, if a language you need is " + "missing please report a bug at bug-guix@gnu.org."))) + (format + port + ";;;###autoload + (defun tree-sitter-langs-install-grammars + (&optional skip-if-installed version os + keep-bundle) + (interactive) + (message \"~a\")) + (defconst tree-sitter-langs--queries-dir + (file-name-as-directory + (concat (file-name-directory + (locate-library \"tree-sitter-langs.el\")) + \"queries\"))) + (defun tree-sitter-langs--bin-dir () \"~a\") + (provide 'tree-sitter-langs-build)" + on-load-message + #$emacs-tree-sitter-langs-grammar-bundle)))))) + (add-after 'unpack 'remove-cask + (lambda _ + (substitute* "script/test" + (("cask") "")))) + (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 + ;; packaged yet. + (add-before 'check 'remove-unused-highlight-queries + (lambda _ + (delete-file-recursively "queries/hcl") + (delete-file-recursively "queries/pgn") + (delete-file-recursively "queries/yaml"))) + (add-after 'install 'install-queries + (lambda _ + (copy-recursively + "queries" + (string-append (elpa-directory #$output) "/queries"))))))) + (home-page "https://emacs-tree-sitter.github.io/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 + +The following languages are currently supported in Guix: + +@itemize +@item Bash +@item C +@item C# +@item C++ +@item Clojure +@item CSS +@item Elixir +@item Elm +@item Go +@item Haskell +@item HTML +@item Java +@item JavaScript +@item JSON +@item Julia +@item Lua +@item Markdown +@item Ocaml +@item PHP +@item Python +@item R +@item Ruby +@item Rust +@item Typescript +@end itemize") + (license license:expat))) -- 2.39.1