(interactive (list (intern
(completing-read
"Language: "
- (mapcar #'car treesit-language-source-alist)))))
+ (mapcar #'car treesit-language-source-alist)))
+ 'interactive))
(when-let ((recipe
(or (assoc lang treesit-language-source-alist)
- (treesit--install-language-grammar-build-recipe
- lang))))
+ (if (eq out-dir 'interactive)
+ (treesit--install-language-grammar-build-recipe
+ lang)
+ (signal 'treesit-error `("Cannot find recipe for this language" ,lang)))))
+ (default-out-dir
+ (or (car treesit--install-language-grammar-out-dir-history)
+ (locate-user-emacs-file "tree-sitter")))
+ (out-dir
+ (if (eq out-dir 'interactive)
+ (read-string
+ (format "Install to (default: %s): "
+ default-out-dir)
+ nil
+ 'treesit--install-language-grammar-out-dir-history
+ default-out-dir)
+ out-dir)))
(condition-case err
- (apply #'treesit--install-language-grammar-1
- (cons out-dir recipe))
+ (progn
+ (apply #'treesit--install-language-grammar-1
+ ;; The nil is OUT-DIR.
+ (cons nil recipe))
+
+ ;; Check that the installed language grammar is loadable.
+ (pcase-let ((`(,available . ,err)
+ (treesit-language-available-p lang t)))
+ (if (not available)
+ (display-warning
+ 'treesit
+ (format "The installed language grammar for %s cannot be located or has problems (%s): %s"
+ lang (nth 0 err)
+ (string-join
+ (mapcar (lambda (x) (format "%s" x))
+ (cdr err))
+ " ")))
+ ;; If success, Save the recipe for the current session.
+ (setf (alist-get lang treesit-language-source-alist)
+ recipe))))
(error
(display-warning
'treesit