Function: treesit-ensure-installed

treesit-ensure-installed is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-ensure-installed LANG)

Documentation

Ensure that the grammar library for the language LANG is installed.

The option treesit-auto-install-grammar defines whether to install the grammar library if it's unavailable.

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-ensure-installed (lang)
  "Ensure that the grammar library for the language LANG is installed.
The option `treesit-auto-install-grammar' defines whether to install
the grammar library if it's unavailable."
  (when (treesit-available-p)
    (or (treesit-ready-p lang t)
        (let ((out-dir (or (seq-find #'file-writable-p
                                     treesit-extra-load-path)
                           (locate-user-emacs-file "tree-sitter"))))
          (when (or (eq treesit-auto-install-grammar 'always)
                    (and (memq treesit-auto-install-grammar '(ask ask-dir))
                         (y-or-n-p (format "\
Tree-sitter grammar for `%s' is missing; install it?" lang))
                         (or (eq treesit-auto-install-grammar 'ask)
                             (progn
                               (setq out-dir (read-directory-name
                                              (format-prompt "\
Install grammar for `%s' to" nil lang)
                                              out-dir
                                              treesit-extra-load-path))
                               (add-to-list 'treesit-extra-load-path out-dir)
                               t))))
            (treesit-install-language-grammar lang out-dir)
            ;; Check that the grammar was installed successfully
            (treesit-ready-p lang))))))