Skip to content

Commit

Permalink
add support install latest grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
lroolle authored and jcs090218 committed Nov 14, 2023
1 parent 32c664e commit 26885d0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tree-sitter-langs-build.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
(require 'pp)
(require 'url)
(require 'tar-mode)
(require 'json)

(eval-when-compile
(require 'subr-x)
Expand Down Expand Up @@ -531,6 +532,39 @@ non-nil."
(when (bound-and-true-p dired-omit-mode)
(dired-omit-mode -1)))))))


(defun tree-sitter-langs-get-latest-tag ()
"Retrieve the latest tag for tree-sitter-langs from GitHub.
In case of retrieval or parsing error, logs an error message and returns nil."
(condition-case nil
(with-current-buffer (url-retrieve-synchronously "https://api.github.com/repos/emacs-tree-sitter/tree-sitter-langs/releases/latest" 'silent 'inhibit-cookies)
(goto-char (point-min))
(re-search-forward "^$")
(delete-region (point) (point-min))
(let ((response (json-read)))
(cdr (assoc 'tag_name response))))
(error
(message "Error retrieving the latest version of tree-sitter-langs.")
nil)))


;;;###autoload
(defun tree-sitter-langs-install-latest-grammar (&optional skip-if-installed os keep-bundle)
"Install the latest version of the tree-sitter-langs grammar bundle.
Automatically retrieves the latest version tag from GitHub.
If SKIP-IF-INSTALLED is non-nil, skips if the latest version is already installed.
OS specifies the operating system.
If KEEP-BUNDLE is non-nil, the downloaded bundle file is not deleted after installation."
(interactive (list 't tree-sitter-langs--os nil))
(message "Fetching the latest version of tree-sitter-langs...")
(let ((latest-tag (tree-sitter-langs-get-latest-tag)))
(if latest-tag
(progn
(message "Latest version retrieved: %s" latest-tag)
(tree-sitter-langs-install-grammars skip-if-installed latest-tag os keep-bundle))
(message "Failed to retrieve the latest version."))))


(defun tree-sitter-langs--copy-query (lang-symbol &optional force)
"Copy highlights.scm file of LANG-SYMBOL to `tree-sitter-langs--queries-dir'.
This assumes the repo has already been set up, for example by
Expand Down

0 comments on commit 26885d0

Please sign in to comment.