emacs-diffs
[Top][All Lists]
Advanced

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

emacs-30 c5925b6ba5f: Fix heex-ts-mode indentation following previews el


From: Yuan Fu
Subject: emacs-30 c5925b6ba5f: Fix heex-ts-mode indentation following previews elixir-mode change
Date: Tue, 10 Sep 2024 23:08:00 -0400 (EDT)

branch: emacs-30
commit c5925b6ba5f7821ea72ebd26b76e405cecaabb8e
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Fix heex-ts-mode indentation following previews elixir-mode change
    
    After the previous fix in elixir-ts-mode (0fd259d166c), embedded heex
    code are indented like this:
    
    1 defmodule Foo do
    2   def foo(assigns) do
    3     ~H"""
    4 <span>
    5   text
    6 </span>
    7     """
    8   end
    9 end
    
    The indent rule finds the beginning of the parent heex node, and uses
    the indentation of that line as anchor with an offset of 0.  Previously
    the parent heex node (fragment) starts at EOL of line 3; after the
    previous commit, it now starts at BOL of line 4.  To fix the
    indentation, I changed the anchor to the beginning of the elixir
    (rather than heex) node at point, which is at EOL at line 3.
    
    * lisp/progmodes/heex-ts-mode.el (heex-ts--indent-rules): Use the elixir
    node that contains the heex code as the anchor, instead of the heex root
    node.
---
 lisp/progmodes/heex-ts-mode.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/heex-ts-mode.el b/lisp/progmodes/heex-ts-mode.el
index 07b8bfdc74f..b527d96b579 100644
--- a/lisp/progmodes/heex-ts-mode.el
+++ b/lisp/progmodes/heex-ts-mode.el
@@ -64,16 +64,18 @@
   (let ((offset heex-ts-indent-offset))
     `((heex
        ((parent-is "fragment")
-        (lambda (node parent &rest _)
+        (lambda (_node _parent bol &rest _)
           ;; If HEEx is embedded indent to parent
           ;; otherwise indent to the bol.
           (if (eq (treesit-language-at (point-min)) 'heex)
               (point-min)
             (save-excursion
-              (goto-char (treesit-node-start parent))
+              (goto-char (treesit-node-start
+                          (treesit-node-at bol 'elixir)))
               (back-to-indentation)
               (point))
-            )) 0)
+            ))
+        0)
        ((node-is "end_tag") parent-bol 0)
        ((node-is "end_component") parent-bol 0)
        ((node-is "end_slot") parent-bol 0)



reply via email to

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