Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement Automatic Latest Version Installation for tree-sitter-langs #278

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -522,6 +523,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
Loading