diff options
| author | Yuan Fu | 2023-05-28 15:31:58 -0700 |
|---|---|---|
| committer | Yuan Fu | 2023-05-28 15:34:25 -0700 |
| commit | 3f4415256793ea0bdb99f8a67f795e68676b6be1 (patch) | |
| tree | 8c1cc5ede389d7718fab13343d9a70b592359520 | |
| parent | c0c7b947baf5e086a857055d18dab04ce13d1f6a (diff) | |
| download | emacs-3f4415256793ea0bdb99f8a67f795e68676b6be1.tar.gz emacs-3f4415256793ea0bdb99f8a67f795e68676b6be1.zip | |
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.
| -rw-r--r-- | lisp/treesit.el | 42 |
1 files 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." | |||
| 2884 | 2884 | ||
| 2885 | Interactively, if `treesit-language-source-alist' doesn't already | 2885 | Interactively, if `treesit-language-source-alist' doesn't already |
| 2886 | have data for building the grammar for LANG, prompt for its | 2886 | have data for building the grammar for LANG, prompt for its |
| 2887 | repository URL and the C/C++ compiler to use. | 2887 | repository URL and the C/C++ compiler to use. The recipe built |
| 2888 | by the prompts are saved for the current session if the | ||
| 2889 | installation is successful and the grammar is loadable. | ||
| 2888 | 2890 | ||
| 2889 | This command requires Git, a C compiler and (sometimes) a C++ compiler, | 2891 | This command requires Git, a C compiler and (sometimes) a C++ compiler, |
| 2890 | and the linker to be installed and on PATH. It also requires that the | 2892 | 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." | |||
| 2901 | (treesit--install-language-grammar-build-recipe | 2903 | (treesit--install-language-grammar-build-recipe |
| 2902 | lang)))) | 2904 | lang)))) |
| 2903 | (condition-case err | 2905 | (condition-case err |
| 2904 | (apply #'treesit--install-language-grammar-1 | 2906 | (progn |
| 2905 | ;; The nil is OUT-DIR. | 2907 | (apply #'treesit--install-language-grammar-1 |
| 2906 | (cons nil recipe)) | 2908 | ;; The nil is OUT-DIR. |
| 2909 | (cons nil recipe)) | ||
| 2910 | |||
| 2911 | ;; Check that the installed language grammar is loadable. | ||
| 2912 | (pcase-let ((`(,available . ,err) | ||
| 2913 | (treesit-language-available-p lang t))) | ||
| 2914 | (if (not available) | ||
| 2915 | (display-warning | ||
| 2916 | 'treesit | ||
| 2917 | (format "The installed language grammar for %s cannot be located or has problems (%s): %s" | ||
| 2918 | lang (nth 0 err) | ||
| 2919 | (string-join | ||
| 2920 | (mapcar (lambda (x) (format "%s" x)) | ||
| 2921 | (cdr err)) | ||
| 2922 | " "))) | ||
| 2923 | ;; If success, Save the recipe for the current session. | ||
| 2924 | (setf (alist-get lang treesit-language-source-alist) | ||
| 2925 | recipe)))) | ||
| 2907 | (error | 2926 | (error |
| 2908 | (display-warning | 2927 | (display-warning |
| 2909 | 'treesit | 2928 | 'treesit |
| 2910 | (format "Error encountered when installing language grammar: %s" | 2929 | (format "Error encountered when installing language grammar: %s" |
| 2911 | err))))) | 2930 | err)))))) |
| 2912 | |||
| 2913 | ;; Check that the installed language grammar is loadable. | ||
| 2914 | (pcase-let ((`(,available . ,err) | ||
| 2915 | (treesit-language-available-p lang t))) | ||
| 2916 | (when (not available) | ||
| 2917 | (display-warning | ||
| 2918 | 'treesit | ||
| 2919 | (format "The installed language grammar for %s cannot be located or has problems (%s): %s" | ||
| 2920 | lang (nth 0 err) | ||
| 2921 | (string-join | ||
| 2922 | (mapcar (lambda (x) (format "%s" x)) | ||
| 2923 | (cdr err)) | ||
| 2924 | " ")))))) | ||
| 2925 | 2931 | ||
| 2926 | (defun treesit--call-process-signal (&rest args) | 2932 | (defun treesit--call-process-signal (&rest args) |
| 2927 | "Run `call-process' with ARGS. | 2933 | "Run `call-process' with ARGS. |