all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: john muhl <jm@pub.pink>
To: 74298@debbugs.gnu.org
Subject: bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode'
Date: Sun, 10 Nov 2024 13:00:31 -0600	[thread overview]
Message-ID: <87ldxq9ank.fsf@pub.pink> (raw)
In-Reply-To: <87v7wu9ar3.fsf@pub.pink> (john muhl's message of "Sun, 10 Nov 2024 12:58:24 -0600")

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-Improve-comment-indenting-in-lua-ts-mode.patch --]
[-- Type: text/x-patch, Size: 3420 bytes --]

From cdcbdeafa2b35a7584b7c4c5a19e999476e3a897 Mon Sep 17 00:00:00 2001
From: john muhl <jm@pub.pink>
Date: Sun, 10 Nov 2024 11:26:33 -0600
Subject: [PATCH] ; Improve comment indenting in 'lua-ts-mode'

* lisp/progmodes/lua-ts-mode.el (lua-ts--simple-indent-rules):
Align single line comments with the surrounding context.
(lua-ts--comment-first-sibling-matcher): Check that comment is
the first sibling.
(lua-ts--multi-line-comment-start): New function.
* test/lisp/progmodes/lua-ts-mode-resources/indent.erts:
Add tests.  (Bug#74298)
---
 lisp/progmodes/lua-ts-mode.el                 | 17 ++++++--
 .../lua-ts-mode-resources/indent.erts         | 42 +++++++++++++++++++
 2 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el
index a7763377177..e5a2fafd279 100644
--- a/lisp/progmodes/lua-ts-mode.el
+++ b/lisp/progmodes/lua-ts-mode.el
@@ -289,7 +289,8 @@ lua-ts--font-lock-settings
 
 (defvar lua-ts--simple-indent-rules
   `((lua
-     ((or (node-is "comment")
+     ((or (and (node-is "comment") (parent-is "chunk"))
+          lua-ts--multi-line-comment-start
           (parent-is "comment_content")
           (parent-is "string_content")
           (node-is "]]"))
@@ -473,9 +474,10 @@ lua-ts--nested-function-last-function-matcher
     (= 1 (length (cadr sparse-tree)))))
 
 (defun lua-ts--comment-first-sibling-matcher (node &rest _)
-  "Matches if NODE if it's previous sibling is a comment."
+  "Matches NODE if its previous sibling is a comment."
   (let ((sibling (treesit-node-prev-sibling node)))
-    (equal "comment" (treesit-node-type sibling))))
+    (and (= 0 (treesit-node-index sibling t))
+         (equal "comment" (treesit-node-type sibling)))))
 
 (defun lua-ts--top-level-function-call-matcher (node &rest _)
   "Matches if NODE is within a top-level function call."
@@ -508,6 +510,15 @@ lua-ts--variable-declaration-continuation-anchor
                         (line-beginning-position))
       (point))))
 
+(defun lua-ts--multi-line-comment-start (node &rest _)
+  "Matches if NODE is the beginning of a multi-line comment."
+  (and node
+       (equal "comment" (treesit-node-type node))
+       (save-excursion
+         (goto-char (treesit-node-start node))
+         (forward-char 2)               ; Skip the -- part.
+         (looking-at "\\[\\["))))
+
 (defvar lua-ts--syntax-table
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?+  "."    table)
diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts
index ba7bad1b452..b0ece4cc261 100644
--- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts
@@ -360,6 +360,10 @@ multi-line
     ]]
   return true
 end
+
+  --[[
+Long comment.
+    ]]
 =-=
 --[[
       Multi-line
@@ -373,6 +377,44 @@ multi-line
     ]]
   return true
 end
+
+  --[[
+Long comment.
+    ]]
+=-=-=
+
+Name: Comment Indent
+
+=-=
+local fn1 = function (a, b)
+-- comment
+return a + b
+end
+
+local tb1 = {
+  first = 1,
+-- comment
+  second = 2,
+}
+
+local tb9 = { one = 1,
+-- comment
+   two = 2 }
+=-=
+local fn1 = function (a, b)
+  -- comment
+  return a + b
+end
+
+local tb1 = {
+  first = 1,
+  -- comment
+  second = 2,
+}
+
+local tb9 = { one = 1,
+	      -- comment
+	      two = 2 }
 =-=-=
 
 Name: Argument Indent
-- 
2.47.0


[-- Attachment #2: Type: text/plain, Size: 260 bytes --]



john muhl <jm@pub.pink> writes:

> Tags: patch
>
> This improves nested comment indenting such that:
>
>   local tbl = {
>     one = 1,
>   -- comment
>     two = 2,
>   }
>
> becomes:
>
>   local tbl = {
>     one = 1,
>     -- comment
>     two = 2,
>   }

  reply	other threads:[~2024-11-10 19:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-10 18:58 bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode' john muhl
2024-11-10 19:00 ` john muhl [this message]
2024-11-14  8:15   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ldxq9ank.fsf@pub.pink \
    --to=jm@pub.pink \
    --cc=74298@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.