:group 'lua-ts
:version "30.1")
+(defcustom lua-ts-indent-continuation-lines t
+ "Controls how multi-line if/else statements are aligned.
+
+If t, then continuation lines are indented by `lua-ts-indent-offset':
+
+ if a
+ and b then
+ print(1)
+ end
+
+If nil, then continuation lines are aligned with the beginning of
+the statement:
+
+ if a
+ and b then
+ print(1)
+ end"
+ :type 'boolean
+ :safe 'booleanp
+ :group 'lua-ts
+ :version "30.1")
+
(defvar lua-ts--builtins
'("assert" "bit32" "collectgarbage" "coroutine" "debug" "dofile"
"error" "getmetatable" "io" "ipairs" "load" "loadfile"
((or (match "end" "function_definition")
(node-is "end"))
standalone-parent 0)
+ ((n-p-gp "expression_list" "assignment_statement" "variable_declaration")
+ lua-ts--variable-declaration-continuation-anchor
+ lua-ts-indent-offset)
+ ((and (parent-is "binary_expression")
+ lua-ts--variable-declaration-continuation)
+ lua-ts--variable-declaration-continuation-anchor
+ lua-ts-indent-offset)
+ ((and (lambda (&rest _) lua-ts-indent-continuation-lines)
+ (parent-is "binary_expression"))
+ standalone-parent lua-ts-indent-offset)
+ ((parent-is "binary_expression") standalone-parent 0)
((or (parent-is "function_declaration")
(parent-is "function_definition")
(parent-is "do_statement")
(treesit-induce-sparse-tree parent #'lua-ts--function-definition-p)))
(= 1 (length (cadr sparse-tree)))))
+(defun lua-ts--variable-declaration-continuation (node &rest _)
+ "Matches if NODE is part of a multi-line variable declaration."
+ (treesit-parent-until node
+ (lambda (p)
+ (equal "variable_declaration"
+ (treesit-node-type p)))))
+
+(defun lua-ts--variable-declaration-continuation-anchor (node &rest _)
+ "Return the start position of the variable declaration for NODE."
+ (save-excursion
+ (goto-char (treesit-node-start
+ (lua-ts--variable-declaration-continuation node)))
+ (when (looking-back (rx bol (* whitespace))
+ (line-beginning-position))
+ (point))))
+
(defvar lua-ts--syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?+ "." table)
}
=-=-=
+Name: Continuation Indent
+
+=-=
+local very_long_variable_name =
+"ok"..
+ "ok"
+local n = a +
+b *
+c /
+1
+local x = "A"..
+"B"
+.."C"
+if a
+ and b
+ and c then
+ if x
+ and y then
+ local x = 1 +
+2 *
+ 3
+ end
+elseif a
+ or b
+ or c then
+end
+=-=
+local very_long_variable_name =
+ "ok"..
+ "ok"
+local n = a +
+ b *
+ c /
+ 1
+local x = "A"..
+ "B"
+ .."C"
+if a
+ and b
+ and c then
+ if x
+ and y then
+ local x = 1 +
+ 2 *
+ 3
+ end
+elseif a
+ or b
+ or c then
+end
+=-=-=
+
Code:
(lambda ()
(setq indent-tabs-mode nil)
end)(i(...))
end end end
=-=-=
+
+Code:
+ (lambda ()
+ (setq indent-tabs-mode nil)
+ (setq lua-ts-indent-continuation-lines nil)
+ (setq lua-ts-indent-offset 2)
+ (lua-ts-mode)
+ (indent-region (point-min) (point-max)))
+
+Name: Unaligned Continuation Indent
+
+=-=
+local n = a +
+ b *
+ c /
+ 1
+if a
+ and b
+and c then
+ if x
+ and y then
+ local x = 1 +
+ 2 *
+ 3
+ end
+elseif a
+ or b
+ or c then
+ if x
+ or y
+ end
+end
+=-=
+local n = a +
+ b *
+ c /
+ 1
+if a
+and b
+and c then
+ if x
+ and y then
+ local x = 1 +
+ 2 *
+ 3
+ end
+elseif a
+or b
+or c then
+ if x
+ or y
+ end
+end
+=-=-=