aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2022-12-31 15:13:50 -0800
committerYuan Fu2022-12-31 16:23:07 -0800
commitddfeee3e8a7b00905e89f36a9ffc0eefdc0d61a4 (patch)
tree1f7af5a7a9852adf2d86621807a4f9899e16ca2f
parent683746978061f3bfc12d4bf524c15649f7b290fa (diff)
downloademacs-ddfeee3e8a7b00905e89f36a9ffc0eefdc0d61a4.tar.gz
emacs-ddfeee3e8a7b00905e89f36a9ffc0eefdc0d61a4.zip
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.
-rw-r--r--lisp/treesit.el49
1 files changed, 38 insertions, 11 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 52983ec0c90..77715798e1a 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2633,6 +2633,29 @@ the grammar's parser.c file resides, defaulting to \"src\".
2633CC and C++ are C and C++ compilers, defaulting to \"cc\" and 2633CC and C++ are C and C++ compilers, defaulting to \"cc\" and
2634\"c++\", respectively.") 2634\"c++\", respectively.")
2635 2635
2636(defun treesit--install-language-grammar-build-recipe (lang)
2637 "Interactively build a recipe for LANG and return it.
2638See `treesit-language-source-alist' for details."
2639 (when (y-or-n-p (format "There is no recipe for %s, do you want to build it interactively?" lang))
2640 (cl-labels ((empty-string-to-nil (string)
2641 (if (equal string "") nil string)))
2642 (list
2643 lang
2644 (read-string
2645 "Enter the URL of the Git repository of the language grammar: ")
2646 (empty-string-to-nil
2647 (read-string
2648 "Enter the tag or branch (default: default branch): "))
2649 (empty-string-to-nil
2650 (read-string
2651 "Enter the subdirectory in which the parser.c file resides (default: \"src\"): "))
2652 (empty-string-to-nil
2653 (read-string
2654 "Enter the C compiler to use (default: auto-detect): "))
2655 (empty-string-to-nil
2656 (read-string
2657 "Enter the C++ compiler to use (default: auto-detect): "))))))
2658
2636(defun treesit-install-language-grammar (lang) 2659(defun treesit-install-language-grammar (lang)
2637 "Build and install the tree-sitter language grammar library for LANG. 2660 "Build and install the tree-sitter language grammar library for LANG.
2638 2661
@@ -2645,17 +2668,21 @@ executable programs, such as the C/C++ compiler and linker."
2645 (interactive (list (intern 2668 (interactive (list (intern
2646 (completing-read 2669 (completing-read
2647 "Language: " 2670 "Language: "
2648 (mapcar #'car treesit-language-source-alist) 2671 (mapcar #'car treesit-language-source-alist)))))
2649 nil t)))) 2672 (when-let ((recipe
2650 (condition-case err 2673 (or (assoc lang treesit-language-source-alist)
2651 (apply #'treesit--install-language-grammar-1 2674 (treesit--install-language-grammar-build-recipe
2652 ;; The nil is OUT-DIR. 2675 lang))))
2653 (cons nil (assoc lang treesit-language-source-alist))) 2676 (condition-case err
2654 (error 2677 (apply #'treesit--install-language-grammar-1
2655 (display-warning 2678 ;; The nil is OUT-DIR.
2656 'treesit 2679 (cons nil recipe))
2657 (format "Error encountered when installing language grammar: %s" 2680 (error
2658 err)))) 2681 (display-warning
2682 'treesit
2683 (format "Error encountered when installing language grammar: %s"
2684 err)))))
2685
2659 ;; Check that the installed language grammar is loadable. 2686 ;; Check that the installed language grammar is loadable.
2660 (pcase-let ((`(,available . ,err) 2687 (pcase-let ((`(,available . ,err)
2661 (treesit-language-available-p lang t))) 2688 (treesit-language-available-p lang t)))