Build recipe interactively in treesit-install-language-grammar
If there is not existing recipe for a language, prompt to build the recipe interactively. * lisp/treesit.el (treesit--install-language-grammar-build-recipe): New functions. (treesit-install-language-grammar): Use the new function.
This commit is contained in:
parent
6837469780
commit
ddfeee3e8a
1 changed files with 38 additions and 11 deletions
|
@ -2633,6 +2633,29 @@ the grammar's parser.c file resides, defaulting to \"src\".
|
||||||
CC and C++ are C and C++ compilers, defaulting to \"cc\" and
|
CC and C++ are C and C++ compilers, defaulting to \"cc\" and
|
||||||
\"c++\", respectively.")
|
\"c++\", respectively.")
|
||||||
|
|
||||||
|
(defun treesit--install-language-grammar-build-recipe (lang)
|
||||||
|
"Interactively build a recipe for LANG and return it.
|
||||||
|
See `treesit-language-source-alist' for details."
|
||||||
|
(when (y-or-n-p (format "There is no recipe for %s, do you want to build it interactively?" lang))
|
||||||
|
(cl-labels ((empty-string-to-nil (string)
|
||||||
|
(if (equal string "") nil string)))
|
||||||
|
(list
|
||||||
|
lang
|
||||||
|
(read-string
|
||||||
|
"Enter the URL of the Git repository of the language grammar: ")
|
||||||
|
(empty-string-to-nil
|
||||||
|
(read-string
|
||||||
|
"Enter the tag or branch (default: default branch): "))
|
||||||
|
(empty-string-to-nil
|
||||||
|
(read-string
|
||||||
|
"Enter the subdirectory in which the parser.c file resides (default: \"src\"): "))
|
||||||
|
(empty-string-to-nil
|
||||||
|
(read-string
|
||||||
|
"Enter the C compiler to use (default: auto-detect): "))
|
||||||
|
(empty-string-to-nil
|
||||||
|
(read-string
|
||||||
|
"Enter the C++ compiler to use (default: auto-detect): "))))))
|
||||||
|
|
||||||
(defun treesit-install-language-grammar (lang)
|
(defun treesit-install-language-grammar (lang)
|
||||||
"Build and install the tree-sitter language grammar library for LANG.
|
"Build and install the tree-sitter language grammar library for LANG.
|
||||||
|
|
||||||
|
@ -2645,17 +2668,21 @@ executable programs, such as the C/C++ compiler and linker."
|
||||||
(interactive (list (intern
|
(interactive (list (intern
|
||||||
(completing-read
|
(completing-read
|
||||||
"Language: "
|
"Language: "
|
||||||
(mapcar #'car treesit-language-source-alist)
|
(mapcar #'car treesit-language-source-alist)))))
|
||||||
nil t))))
|
(when-let ((recipe
|
||||||
(condition-case err
|
(or (assoc lang treesit-language-source-alist)
|
||||||
(apply #'treesit--install-language-grammar-1
|
(treesit--install-language-grammar-build-recipe
|
||||||
;; The nil is OUT-DIR.
|
lang))))
|
||||||
(cons nil (assoc lang treesit-language-source-alist)))
|
(condition-case err
|
||||||
(error
|
(apply #'treesit--install-language-grammar-1
|
||||||
(display-warning
|
;; The nil is OUT-DIR.
|
||||||
'treesit
|
(cons nil recipe))
|
||||||
(format "Error encountered when installing language grammar: %s"
|
(error
|
||||||
err))))
|
(display-warning
|
||||||
|
'treesit
|
||||||
|
(format "Error encountered when installing language grammar: %s"
|
||||||
|
err)))))
|
||||||
|
|
||||||
;; Check that the installed language grammar is loadable.
|
;; Check that the installed language grammar is loadable.
|
||||||
(pcase-let ((`(,available . ,err)
|
(pcase-let ((`(,available . ,err)
|
||||||
(treesit-language-available-p lang t)))
|
(treesit-language-available-p lang t)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue