Skip to content

Commit 26885d0

Browse files
lroollejcs090218
authored andcommitted
add support install latest grammar
1 parent 32c664e commit 26885d0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tree-sitter-langs-build.el

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
(require 'pp)
1919
(require 'url)
2020
(require 'tar-mode)
21+
(require 'json)
2122

2223
(eval-when-compile
2324
(require 'subr-x)
@@ -531,6 +532,39 @@ non-nil."
531532
(when (bound-and-true-p dired-omit-mode)
532533
(dired-omit-mode -1)))))))
533534

535+
536+
(defun tree-sitter-langs-get-latest-tag ()
537+
"Retrieve the latest tag for tree-sitter-langs from GitHub.
538+
In case of retrieval or parsing error, logs an error message and returns nil."
539+
(condition-case nil
540+
(with-current-buffer (url-retrieve-synchronously "https://api.github.com/repos/emacs-tree-sitter/tree-sitter-langs/releases/latest" 'silent 'inhibit-cookies)
541+
(goto-char (point-min))
542+
(re-search-forward "^$")
543+
(delete-region (point) (point-min))
544+
(let ((response (json-read)))
545+
(cdr (assoc 'tag_name response))))
546+
(error
547+
(message "Error retrieving the latest version of tree-sitter-langs.")
548+
nil)))
549+
550+
551+
;;;###autoload
552+
(defun tree-sitter-langs-install-latest-grammar (&optional skip-if-installed os keep-bundle)
553+
"Install the latest version of the tree-sitter-langs grammar bundle.
554+
Automatically retrieves the latest version tag from GitHub.
555+
If SKIP-IF-INSTALLED is non-nil, skips if the latest version is already installed.
556+
OS specifies the operating system.
557+
If KEEP-BUNDLE is non-nil, the downloaded bundle file is not deleted after installation."
558+
(interactive (list 't tree-sitter-langs--os nil))
559+
(message "Fetching the latest version of tree-sitter-langs...")
560+
(let ((latest-tag (tree-sitter-langs-get-latest-tag)))
561+
(if latest-tag
562+
(progn
563+
(message "Latest version retrieved: %s" latest-tag)
564+
(tree-sitter-langs-install-grammars skip-if-installed latest-tag os keep-bundle))
565+
(message "Failed to retrieve the latest version."))))
566+
567+
534568
(defun tree-sitter-langs--copy-query (lang-symbol &optional force)
535569
"Copy highlights.scm file of LANG-SYMBOL to `tree-sitter-langs--queries-dir'.
536570
This assumes the repo has already been set up, for example by

0 commit comments

Comments
 (0)