aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2025-04-23 20:17:46 +0300
committerJuri Linkov2025-04-23 20:17:46 +0300
commit261a965ff1a423c9dc0ee7c89974e4fc3c16b863 (patch)
tree0271730a4335458903f0c6c74b5f9b3f0a25d960
parentd3f1f4923f73db617a69ac5d26d08809f814a811 (diff)
downloademacs-261a965ff1a423c9dc0ee7c89974e4fc3c16b863.tar.gz
emacs-261a965ff1a423c9dc0ee7c89974e4fc3c16b863.zip
Add the keyword ':copy-queries' to 'treesit-language-source-alist'.
* lisp/treesit-x.el (define-treesit-generic-mode): Add keyword ':copy-queries t' to the end of 'source'. * lisp/treesit.el (treesit-language-source-alist): Document the keyword ':copy-queries'. (treesit--install-language-grammar-1): Add &rest args. Process the keyword args. Call 'treesit--copy-queries' when :copy-queries is non-nil. (treesit--copy-queries): Add arg 'source-dir'. Copy queries from source-dir as well. Copy only the file "highlights.scm".
-rw-r--r--lisp/treesit-x.el2
-rw-r--r--lisp/treesit.el36
2 files changed, 28 insertions, 10 deletions
diff --git a/lisp/treesit-x.el b/lisp/treesit-x.el
index 1de4b9765e8..b0e3863c034 100644
--- a/lisp/treesit-x.el
+++ b/lisp/treesit-x.el
@@ -110,7 +110,7 @@ of `define-treesit-generic-mode'.
110 (_ (pop body)))) 110 (_ (pop body))))
111 111
112 (when (stringp source) 112 (when (stringp source)
113 (setq source (list 'quote (ensure-list source)))) 113 (setq source (list 'quote (list source nil nil nil nil nil :copy-queries t))))
114 (when (stringp auto-mode) 114 (when (stringp auto-mode)
115 (setq auto-mode (list 'quote (ensure-list auto-mode)))) 115 (setq auto-mode (list 'quote (ensure-list auto-mode))))
116 116
diff --git a/lisp/treesit.el b/lisp/treesit.el
index bf5c1ed5f6c..2794fdfe91f 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -4962,7 +4962,7 @@ window."
4962 4962
4963The value should be an alist where each element has the form 4963The value should be an alist where each element has the form
4964 4964
4965 (LANG . (URL REVISION SOURCE-DIR CC C++ COMMIT)) 4965 (LANG . (URL REVISION SOURCE-DIR CC C++ COMMIT [KEYWORD VALUE]...))
4966 4966
4967Only LANG and URL are mandatory. LANG is the language symbol. 4967Only LANG and URL are mandatory. LANG is the language symbol.
4968URL is the URL of the grammar's Git repository or a directory 4968URL is the URL of the grammar's Git repository or a directory
@@ -4977,7 +4977,13 @@ SOURCE-DIR is the relative subdirectory in the repository in which
4977the grammar's parser.c file resides, defaulting to \"src\". 4977the grammar's parser.c file resides, defaulting to \"src\".
4978 4978
4979CC and C++ are C and C++ compilers, defaulting to \"cc\" and 4979CC and C++ are C and C++ compilers, defaulting to \"cc\" and
4980\"c++\", respectively.") 4980\"c++\", respectively.
4981
4982The currently supported keywords:
4983
4984`:copy-queries' when non-nil specifies whether to copy the files
4985in the \"queries\" directory from the source directory to the
4986installation directory.")
4981 4987
4982(defun treesit--install-language-grammar-build-recipe (lang) 4988(defun treesit--install-language-grammar-build-recipe (lang)
4983 "Interactively produce a download/build recipe for LANG and return it. 4989 "Interactively produce a download/build recipe for LANG and return it.
@@ -5161,7 +5167,7 @@ clone if `treesit--install-language-grammar-blobless' is t."
5161 (apply #'treesit--call-process-signal args))) 5167 (apply #'treesit--call-process-signal args)))
5162 5168
5163(defun treesit--install-language-grammar-1 5169(defun treesit--install-language-grammar-1
5164 (out-dir lang url &optional revision source-dir cc c++ commit) 5170 (out-dir lang url &optional revision source-dir cc c++ commit &rest args)
5165 "Compile and install a tree-sitter language grammar library. 5171 "Compile and install a tree-sitter language grammar library.
5166 5172
5167OUT-DIR is the directory to put the compiled library file. If it 5173OUT-DIR is the directory to put the compiled library file. If it
@@ -5183,7 +5189,14 @@ If anything goes wrong, this function signals an `treesit-error'."
5183 (workdir (if url-is-dir 5189 (workdir (if url-is-dir
5184 maybe-repo-dir 5190 maybe-repo-dir
5185 (expand-file-name "repo"))) 5191 (expand-file-name "repo")))
5186 version) 5192 copy-queries version)
5193
5194 ;; Process the keyword args.
5195 (while (keywordp (car args))
5196 (pcase (pop args)
5197 (:copy-queries (setq copy-queries (pop args)))
5198 (_ (pop args))))
5199
5187 (unwind-protect 5200 (unwind-protect
5188 (with-temp-buffer 5201 (with-temp-buffer
5189 (if url-is-dir 5202 (if url-is-dir
@@ -5194,7 +5207,8 @@ If anything goes wrong, this function signals an `treesit-error'."
5194 (treesit--git-checkout-branch workdir commit)) 5207 (treesit--git-checkout-branch workdir commit))
5195 (setq version (treesit--language-git-revision workdir)) 5208 (setq version (treesit--language-git-revision workdir))
5196 (treesit--build-grammar workdir out-dir lang source-dir cc c++) 5209 (treesit--build-grammar workdir out-dir lang source-dir cc c++)
5197 (treesit--copy-queries workdir out-dir lang)) 5210 (when copy-queries
5211 (treesit--copy-queries workdir out-dir lang source-dir)))
5198 ;; Remove workdir if it's not a repo owned by user and we 5212 ;; Remove workdir if it's not a repo owned by user and we
5199 ;; managed to create it in the first place. 5213 ;; managed to create it in the first place.
5200 (when (and (not url-is-dir) (file-exists-p workdir)) 5214 (when (and (not url-is-dir) (file-exists-p workdir))
@@ -5273,14 +5287,18 @@ If anything goes wrong, this function signals an `treesit-error'."
5273 (ignore-errors (delete-file old-fname))) 5287 (ignore-errors (delete-file old-fname)))
5274 (message "Library installed to %s/%s" out-dir lib-name)))) 5288 (message "Library installed to %s/%s" out-dir lib-name))))
5275 5289
5276(defun treesit--copy-queries (workdir out-dir lang) 5290(defun treesit--copy-queries (workdir out-dir lang source-dir)
5277 "Copy the LANG \"queries\" directory from WORKDIR to OUT-DIR." 5291 "Copy files in LANG \"queries\" directory from WORKDIR to OUT-DIR.
5278 (let* ((query-dir (expand-file-name "queries" workdir)) 5292The copied query files are queries/highlights.scm."
5293 (let* ((query-dir (expand-file-name
5294 (or (and source-dir (format "%s/../queries" source-dir))
5295 "queries")
5296 workdir))
5279 (dest-dir (expand-file-name (format "queries/%s" lang) out-dir))) 5297 (dest-dir (expand-file-name (format "queries/%s" lang) out-dir)))
5280 (when (file-directory-p query-dir) 5298 (when (file-directory-p query-dir)
5281 (unless (file-directory-p dest-dir) 5299 (unless (file-directory-p dest-dir)
5282 (make-directory dest-dir t)) 5300 (make-directory dest-dir t))
5283 (dolist (file (directory-files query-dir t "\\.scm\\'" t)) 5301 (dolist (file (directory-files query-dir t "highlights\\.scm\\'" t))
5284 (copy-file file (expand-file-name (file-name-nondirectory file) dest-dir) t))))) 5302 (copy-file file (expand-file-name (file-name-nondirectory file) dest-dir) t)))))
5285 5303
5286(defcustom treesit-auto-install-grammar 'ask 5304(defcustom treesit-auto-install-grammar 'ask