Subject: bug#62155: 30.0.50; elixir-ts-mode.elc warning

From: Wilhelm Kirschbaum <[email-masked]>
Date: Mon, 13 Mar 2023 22:07:27 +0200

Eli Zaretskii <[email-masked]> writes:

>> Cc: [email-masked], [email-masked]
>> From: Wilhelm Kirschbaum <[email-masked]>
>> Date: Mon, 13 Mar 2023 15:08:10 +0200
>> 
>> I can see there is still an issue with loading heex-ts-mode 
>> from 
>> elixir-ts-mode, but not quite sure how to
>> immediately resolve it. I will have a look in a couple of 
>> hours.
>
> One possibility is to add defvar for each variable defined by
> heex-ts-mode that elixir-ts-mode needs to use, and remove the 
> require
> of heex-ts-mode.  Since heex-ts-mode is loaded at run time, I 
> think
> this should be enough.
>

Thank you, this seems to work well.

>From 07a8a8d396a91fd4b8dcb57cc98ef30784601ac3 Mon Sep 17 00:00:00 2001
From: Wilhelm H Kirschbaum <[email-masked]>
Date: Mon, 13 Mar 2023 21:47:50 +0200
Subject: [PATCH] Fix elixir-ts-mode.elc warning (bug#62155)

* lisp/progmodes/elixir-ts-mode.el: Only require heex-ts-mode once
elixir-ts-mode loads to avoid calling (treesit-ready-p 'heex)
during byte-compilation.
---
 lisp/progmodes/elixir-ts-mode.el | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/elixir-ts-mode.el b/lisp/progmodes/elixir-ts-mode.el
index 8adf647b081..da83e7d6c5a 100644
--- a/lisp/progmodes/elixir-ts-mode.el
+++ b/lisp/progmodes/elixir-ts-mode.el
@@ -44,7 +44,6 @@
 ;;; Code:
 
 (require 'treesit)
-(require 'heex-ts-mode)
 (eval-when-compile (require 'rx))
 
 (declare-function treesit-parser-create "treesit.c")
@@ -480,6 +479,10 @@ elixir-ts--treesit-range-rules
      :host 'elixir
      '((sigil (sigil_name) @name (:match "^[HF]$" @name) (quoted_content) @heex)))))
 
+(defvar heex-ts--sexp-regexp)
+(defvar heex-ts--indent-rules)
+(defvar heex-ts--font-lock-settings)
+
 (defun elixir-ts--forward-sexp (&optional arg)
   "Move forward across one balanced expression (sexp).
 With ARG, do it many times.  Negative ARG means move backward."
@@ -566,8 +569,12 @@ elixir-ts-mode
   (when (treesit-ready-p 'elixir)
     ;; The HEEx parser has to be created first for elixir to ensure elixir
     ;; is the first language when looking for treesit ranges.
-    (if (treesit-ready-p 'heex)
-        (treesit-parser-create 'heex))
+    (when (treesit-ready-p 'heex)
+      ;; Require heex-ts-mode only when we load elixir-ts-mode
+      ;; so that we don't get a tree-sitter compilation warning for
+      ;; elixir-ts-mode.
+      (require 'heex-ts-mode)
+      (treesit-parser-create 'heex))
 
     (treesit-parser-create 'elixir)
 
-- 
2.39.2