From c1c40dea72c0ea68c259fb82749ddc6e7bf41890 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo Date: Fri, 7 Jun 2024 12:29:25 +0200 Subject: [PATCH] Do not run treesit-parser-create if HTML parser is unavailable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/textmodes/html-ts-mode.el: replaced ‘unless’ with ‘if'. --- lisp/textmodes/html-ts-mode.el | 88 +++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/lisp/textmodes/html-ts-mode.el b/lisp/textmodes/html-ts-mode.el index 235e1055fa9..4c8c6e77f8a 100644 --- a/lisp/textmodes/html-ts-mode.el +++ b/lisp/textmodes/html-ts-mode.el @@ -89,50 +89,50 @@ html-ts-mode "Major mode for editing Html, powered by tree-sitter." :group 'html - (unless (treesit-ready-p 'html) - (error "Tree-sitter for HTML isn't available")) - - (treesit-parser-create 'html) - - ;; Indent. - (setq-local treesit-simple-indent-rules html-ts-mode--indent-rules) - - ;; Navigation. - (setq-local treesit-defun-type-regexp "element") - - (setq-local treesit-defun-name-function #'html-ts-mode--defun-name) - - (setq-local treesit-thing-settings - `((html - (sexp ,(regexp-opt '("element" - "text" - "attribute" - "value"))) - (sentence "tag") - (text ,(regexp-opt '("comment" "text")))))) - - ;; Font-lock. - (setq-local treesit-font-lock-settings html-ts-mode--font-lock-settings) - (setq-local treesit-font-lock-feature-list - '((comment keyword definition) - (property string) - () ())) - - ;; Imenu. - (setq-local treesit-simple-imenu-settings - '(("Element" "\\`tag_name\\'" nil nil))) - - ;; Outline minor mode. - (setq-local treesit-outline-predicate "\\`element\\'") - ;; `html-ts-mode' inherits from `html-mode' that sets - ;; regexp-based outline variables. So need to restore - ;; the default values of outline variables to be able - ;; to use `treesit-outline-predicate' above. - (kill-local-variable 'outline-regexp) - (kill-local-variable 'outline-heading-end-regexp) - (kill-local-variable 'outline-level) - - (treesit-major-mode-setup)) + (if (treesit-ready-p 'html) + (error "Tree-sitter for HTML isn't available") + + (treesit-parser-create 'html) + + ;; Indent. + (setq-local treesit-simple-indent-rules html-ts-mode--indent-rules) + + ;; Navigation. + (setq-local treesit-defun-type-regexp "element") + + (setq-local treesit-defun-name-function #'html-ts-mode--defun-name) + + (setq-local treesit-thing-settings + `((html + (sexp ,(regexp-opt '("element" + "text" + "attribute" + "value"))) + (sentence "tag") + (text ,(regexp-opt '("comment" "text")))))) + + ;; Font-lock. + (setq-local treesit-font-lock-settings html-ts-mode--font-lock-settings) + (setq-local treesit-font-lock-feature-list + '((comment keyword definition) + (property string) + () ())) + + ;; Imenu. + (setq-local treesit-simple-imenu-settings + '(("Element" "\\`tag_name\\'" nil nil))) + + ;; Outline minor mode. + (setq-local treesit-outline-predicate "\\`element\\'") + ;; `html-ts-mode' inherits from `html-mode' that sets + ;; regexp-based outline variables. So need to restore + ;; the default values of outline variables to be able + ;; to use `treesit-outline-predicate' above. + (kill-local-variable 'outline-regexp) + (kill-local-variable 'outline-heading-end-regexp) + (kill-local-variable 'outline-level) + + (treesit-major-mode-setup))) (derived-mode-add-parents 'html-ts-mode '(html-mode)) -- 2.45.2