Subject: Re: bug#77017: 31.0.50; Build warning from mhtml-ts-mode

From: Vincenzo Pupillo <[email-masked]>
Date: Fri, 04 Apr 2025 14:29:45 +0200

I'm sorry. The attached patch should fix the problem. I'm not sure about the 
commit message, since I also modified html-ts-mode.

I recompiled emacs without the grammars and the warning problem shows up for 
other major modes as well.

Vincenzo

In data domenica 30 marzo 2025 08:41:12 Ora legale dell’Europa centrale, Juri 
Linkov ha scritto:
> > --- a/lisp/textmodes/mhtml-ts-mode.el
> > +++ b/lisp/textmodes/mhtml-ts-mode.el
> > @@ -50,13 +50,23 @@
> > 
> >  ;;; Code:
> >  
> >  (require 'treesit)
> > 
> > -(require 'html-ts-mode)
> > 
> >  (require 'css-mode) ;; for embed css into html
> >  (require 'js) ;; for embed javascript into html
> 
> This change broke loading of mhtml-ts-mode:
> 
> 0. emacs -Q
> 1. visit an html file
> 2. M-x mhtml-ts-mode
> 
> Debugger entered--Lisp error: (void-variable
> html-ts-mode--treesit-font-lock-feature-list) (defvar
> mhtml-ts-mode--treesit-font-lock-feature-list ...)
>   command-execute(mhtml-ts-mode record)
>   execute-extended-command(nil "mhtml-ts-mode" nil)
>   funcall-interactively(execute-extended-command nil "mhtml-ts-mode" nil)
>   command-execute(execute-extended-command)

>From 6fe6791f8a928d163198558aa12cb20ef2051276 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Fri, 4 Apr 2025 13:52:28 +0200
Subject: [PATCH] ; Fix last change (bug#77017)

* lisp/textmodes/html-ts-mode.el
(html-ts-mode): Avoid the warning if the html language library is not
installed.
Avoids warning if html language library is not installed
when trying to associate mode with filename patterns.
* lisp/textmodes/html-ts-mode.el: Revert the last changes.
Avoids warning if any of the html, javascript, css language libraries
are not installed when attempting to associate mode with filename
templates.
---
 lisp/textmodes/html-ts-mode.el  |  4 ++--
 lisp/textmodes/mhtml-ts-mode.el | 16 ++--------------
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/lisp/textmodes/html-ts-mode.el b/lisp/textmodes/html-ts-mode.el
index 5df489db3e7..30d1f080b96 100644
--- a/lisp/textmodes/html-ts-mode.el
+++ b/lisp/textmodes/html-ts-mode.el
@@ -144,7 +144,7 @@ html-ts-mode
   "Major mode for editing Html, powered by tree-sitter."
   :group 'html
 
-  (unless (treesit-ready-p 'html)
+  (unless (treesit-ready-p 'html t)
     (error "Tree-sitter for HTML isn't available"))
 
   (setq treesit-primary-parser (treesit-parser-create 'html))
@@ -180,7 +180,7 @@ html-ts-mode
 
 (derived-mode-add-parents 'html-ts-mode '(html-mode))
 
-(if (treesit-ready-p 'html)
+(if (treesit-ready-p 'html t)
     (add-to-list 'auto-mode-alist '("\\.html\\'" . html-ts-mode)))
 
 (provide 'html-ts-mode)
diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el
index 22c0455a4ee..25af6a0a1e0 100644
--- a/lisp/textmodes/mhtml-ts-mode.el
+++ b/lisp/textmodes/mhtml-ts-mode.el
@@ -52,21 +52,11 @@
 (require 'treesit)
 (require 'css-mode) ;; for embed css into html
 (require 'js) ;; for embed javascript into html
+(require 'html-ts-mode)
 
 (eval-when-compile
   (require 'rx))
 
-;; Prevent compile warnings.
-(defvar html-ts-mode-indent-offset)
-(defvar html-ts-mode--treesit-font-lock-feature-list)
-(defvar html-ts-mode--font-lock-settings)
-(defvar html-ts-mode--treesit-things-settings)
-(defvar html-ts-mode--treesit-defun-type-regexp)
-(defvar html-ts-mode--indent-rules)
-(defvar html-ts-mode--treesit-simple-imenu-settings)
-(declare-function html-ts-mode--outline-predicate "html-ts-mode.el")
-(declare-function html-ts-mode--defun-name "html-ts-mode.el")
-
 ;; This tells the byte-compiler where the functions are defined.
 ;; Is only needed when a file needs to be able to byte-compile
 ;; in a Emacs not built with tree-sitter library.
@@ -463,8 +453,6 @@ mhtml-ts-mode
       (error "Tree-sitter parsers for HTML isn't available.  You can
     install the parsers with M-x `mhtml-ts-mode-install-parsers'")
 
-    (require 'html-ts-mode)
-
     ;; When an language is embedded, you should initialize some variable
     ;; just like it's done in the original mode.
 
@@ -601,7 +589,7 @@ mhtml-ts-mode
 ;; Add some extra parents.
 (derived-mode-add-parents 'mhtml-ts-mode '(css-mode js-mode))
 
-(when (and (treesit-ready-p 'html) (treesit-ready-p 'javascript) (treesit-ready-p 'css))
+(when (and (treesit-ready-p 'html t) (treesit-ready-p 'javascript t) (treesit-ready-p 'css t))
   (add-to-list
    'auto-mode-alist '("\\.[sx]?html?\\(\\.[a-zA-Z_]+\\)?\\'" . mhtml-ts-mode)))
 
-- 
2.49.0