mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-21 06:55:39 +00:00
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)
This commit is contained in:
parent
6bc44ccf28
commit
d592832504
@ -289,7 +289,8 @@ values of OVERRIDE."
|
||||
|
||||
(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 @@ values of OVERRIDE."
|
||||
(= 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 @@ values of OVERRIDE."
|
||||
(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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user