Rename 'treesit-auto-install' to 'treesit-auto-install-grammar'
* etc/NEWS: * lisp/treesit.el (treesit-auto-install-grammar): Rename from 'treesit-auto-install'; all users changed. Doc fix. (treesit-ensure-installed): Doc fix.
This commit is contained in:
parent
6430654b4d
commit
5ec6613f13
2 changed files with 26 additions and 17 deletions
6
etc/NEWS
6
etc/NEWS
|
@ -549,8 +549,10 @@ This variable has no effect when Transient Mark mode is off.
|
|||
|
||||
** Tree-sitter
|
||||
|
||||
*** New user option 'treesit-auto-install'.
|
||||
It controls the automatic installation of tree-sitter grammars.
|
||||
*** New user option 'treesit-auto-install-grammar'.
|
||||
It controls the automatic installation of tree-sitter grammar libraries
|
||||
needed for tree-sitter based modes, if these grammar libraries are not
|
||||
available when such modes are turned on.
|
||||
|
||||
*** The file treesit-x.el defines a number of simple tree-sitter modes.
|
||||
Using the new macro 'define-treesit-generic-mode', generic modes are
|
||||
|
|
|
@ -5276,25 +5276,32 @@ If anything goes wrong, this function signals an `treesit-error'."
|
|||
(dolist (file (directory-files query-dir t "\\.scm\\'" t))
|
||||
(copy-file file (expand-file-name (file-name-nondirectory file) dest-dir) t)))))
|
||||
|
||||
(defcustom treesit-auto-install 'ask
|
||||
"Automatic installation of a language grammar.
|
||||
If `ask', prompt for a confirmation before installing the required
|
||||
language grammar. If `always', silently install the grammar.
|
||||
If nil or `never' or anything else, don't install the grammar
|
||||
even while visiting a file in the mode that requires such grammar."
|
||||
:type '(choice (const :tag "Never try to install grammar" never)
|
||||
(const :tag "Always install grammar automatically" always)
|
||||
(const :tag "Ask whether to install grammar" ask))
|
||||
(defcustom treesit-auto-install-grammar 'ask
|
||||
"Whether to install trere-sitter language grammar libraries when needed.
|
||||
This controls whether Emacs will install missing grammar libraries
|
||||
when they are needed by some tree-sitter based mode.
|
||||
If `ask', ask for confirmation before installing the required grammar library.
|
||||
If `always', install the grammar library without asking.
|
||||
If nil or `never' or anything else, don't install the grammar library
|
||||
even while visiting a file in the mode that requires such grammar; this
|
||||
might dispolay a warning and/or fail to turn on the mode."
|
||||
:type '(choice (const :tag "Never install grammar libraries" never)
|
||||
(const :tag "Always automatically install grammar libraries"
|
||||
always)
|
||||
(const :tag "Ask whether to install missing grammar libraries"
|
||||
ask))
|
||||
:version "31.1")
|
||||
|
||||
(defun treesit-ensure-installed (lang)
|
||||
"Ensure that the grammar for the language LANG is installed.
|
||||
The option `treesit-auto-install' defines whether to install it
|
||||
automatically, or ask for a confirmation."
|
||||
"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."
|
||||
(or (treesit-ready-p lang t)
|
||||
(when (or (eq treesit-auto-install 'always)
|
||||
(and (eq treesit-auto-install 'ask)
|
||||
(y-or-n-p (format "Install grammar for `%s'?" lang))))
|
||||
(when (or (eq treesit-auto-install-grammar 'always)
|
||||
(and (eq treesit-auto-install-grammar 'ask)
|
||||
(y-or-n-p (format "\
|
||||
Tree-sitter grammar for `%s' is missing; install it?"
|
||||
lang))))
|
||||
(treesit-install-language-grammar lang)
|
||||
;; Check that the grammar was installed successfully
|
||||
(treesit-ready-p lang))))
|
||||
|
|
Loading…
Add table
Reference in a new issue