emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 3f441525679: Save the tree-sitter grammar recipe when installin


From: Yuan Fu
Subject: emacs-29 3f441525679: Save the tree-sitter grammar recipe when installing a grammar
Date: Sun, 28 May 2023 18:50:28 -0400 (EDT)

branch: emacs-29
commit 3f4415256793ea0bdb99f8a67f795e68676b6be1
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Save the tree-sitter grammar recipe when installing a grammar
    
    Raised in bug#63750, but not the main subject of it.
    
    * lisp/treesit.el (treesit-install-language-grammar): Save the recipe
    to treesit-language-source-alist when installation is successful.
---
 lisp/treesit.el | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index d7502560fea..3ec4fbc5c91 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2884,7 +2884,9 @@ See `treesit-language-source-alist' for details."
 
 Interactively, if `treesit-language-source-alist' doesn't already
 have data for building the grammar for LANG, prompt for its
-repository URL and the C/C++ compiler to use.
+repository URL and the C/C++ compiler to use.  The recipe built
+by the prompts are saved for the current session if the
+installation is successful and the grammar is loadable.
 
 This command requires Git, a C compiler and (sometimes) a C++ compiler,
 and the linker to be installed and on PATH.  It also requires that the
@@ -2901,27 +2903,31 @@ executable programs, such as the C/C++ compiler and 
linker."
                   (treesit--install-language-grammar-build-recipe
                    lang))))
     (condition-case err
-        (apply #'treesit--install-language-grammar-1
-               ;; The nil is OUT-DIR.
-               (cons nil 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
         (format "Error encountered when installing language grammar: %s"
-                err)))))
-
-  ;; Check that the installed language grammar is loadable.
-  (pcase-let ((`(,available . ,err)
-               (treesit-language-available-p lang t)))
-    (when (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))
-                " "))))))
+                err))))))
 
 (defun treesit--call-process-signal (&rest args)
   "Run `call-process' with ARGS.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]