all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode'
@ 2024-11-10 18:58 john muhl
  2024-11-10 19:00 ` john muhl
  0 siblings, 1 reply; 3+ messages in thread
From: john muhl @ 2024-11-10 18:58 UTC (permalink / raw)
  To: 74298

Tags: patch

This improves nested comment indenting such that:

  local tbl = {
    one = 1,
  -- comment
    two = 2,
  }

becomes:

  local tbl = {
    one = 1,
    -- comment
    two = 2,
  }





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode'
  2024-11-10 18:58 bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode' john muhl
@ 2024-11-10 19:00 ` john muhl
  2024-11-14  8:15   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: john muhl @ 2024-11-10 19:00 UTC (permalink / raw)
  To: 74298

[-- 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,
>   }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode'
  2024-11-10 19:00 ` john muhl
@ 2024-11-14  8:15   ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2024-11-14  8:15 UTC (permalink / raw)
  To: john muhl; +Cc: 74298-done

> From: john muhl <jm@pub.pink>
> Date: Sun, 10 Nov 2024 13:00:31 -0600
> 
> >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'

Thanks, installed on the emacs-30 branch, and closing the bug.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-14  8:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-10 18:58 bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode' john muhl
2024-11-10 19:00 ` john muhl
2024-11-14  8:15   ` Eli Zaretskii

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.