From: john muhl Date: Mon, 10 Mar 2025 01:40:58 +0000 (-0500) Subject: Simplify and improve indent rules in 'lua-ts-mode' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=19c9f7fee8e9a7c60a20deefe9f33de83c15b9db;p=emacs.git Simplify and improve indent rules in 'lua-ts-mode' * lisp/progmodes/lua-ts-mode.el (c-ts-common): Require it. (lua-ts-mode): Set 'c-ts-common' variables. (lua-ts--simple-indent-rules): Replace custom indent rules for tables, arguments and parameters with 'c-ts-common-baseline-indent-rule'. Improve consistency of indentation for IIFEs and nested functions. (lua-ts--variable-declaration-continuation) (lua-ts--variable-declaration-continuation-anchor): Reformat. (lua-ts--comment-first-sibling-matcher) (lua-ts--first-child-matcher, lua-ts--first-real-sibling-anchor) (lua-ts--function-definition-p, lua-ts--g-g-g-parent) (lua-ts--g-g-parent, lua-ts--nested-function-argument-matcher) (lua-ts--nested-function-block-include-matcher) (lua-ts--nested-function-block-matcher) (lua-ts--nested-function-end-argument-matcher) (lua-ts--nested-function-end-matcher) (lua-ts--nested-function-last-function-matcher) (lua-ts--top-level-function-call-matcher): Remove. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Update tests. (Bug#76986) (cherry picked from commit 1528d315643d864204f327acb4ec19dd8d859de8) --- diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index b4025c23649..31a1a2b8aea 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -40,6 +40,7 @@ ;;; Code: +(require 'c-ts-common) (require 'comint) (require 'treesit) (treesit-declare-unavailable-functions) @@ -286,12 +287,19 @@ values of OVERRIDE." (defvar lua-ts--simple-indent-rules `((lua + ;; Handle multi-line strings and comments. ((or (and (node-is "comment") (parent-is "chunk")) lua-ts--multi-line-comment-start (parent-is "comment_content") (parent-is "string_content") (or (node-is "]]") (node-is "comment_end"))) no-indent 0) + + ;; Handle multiple "end" statements on a single line. + ((and (node-is "end") lua-ts--end-line-matcher) + standalone-parent lua-ts--end-indent-offset) + + ;; Handle tables in the arguments of a function call. ((and (n-p-gp "field" "table_constructor" "arguments") lua-ts--multi-arg-function-call-matcher lua-ts--last-arg-function-call-matcher) @@ -300,75 +308,44 @@ values of OVERRIDE." lua-ts--multi-arg-function-call-matcher lua-ts--last-arg-function-call-matcher) standalone-parent 0) - ((and (n-p-gp "field" "table_constructor" "arguments") + ((and (match "field" "table_constructor" nil 1 1) lua-ts--multi-arg-function-call-matcher) parent lua-ts-indent-offset) ((and (n-p-gp "}" "table_constructor" "arguments") lua-ts--multi-arg-function-call-matcher) parent 0) - ((or (node-is "do") - (node-is "then") - (node-is "elseif_statement") - (node-is "else_statement") - (node-is "until") - (node-is ")") - (node-is "}")) - standalone-parent 0) - ((match null "table_constructor") - standalone-parent lua-ts-indent-offset) - ((or (and (parent-is "arguments") lua-ts--first-child-matcher) - (and (parent-is "parameters") lua-ts--first-child-matcher) - (and (parent-is "table_constructor") lua-ts--first-child-matcher)) - standalone-parent lua-ts-indent-offset) - ((and (not lua-ts--comment-first-sibling-matcher) - (or (parent-is "arguments") - (parent-is "parameters") - (parent-is "table_constructor"))) - lua-ts--first-real-sibling-anchor 0) - ((or (parent-is "arguments") - (parent-is "parameters") - (parent-is "table_constructor")) - standalone-parent lua-ts-indent-offset) - ((and (n-p-gp "block" "function_definition" "parenthesized_expression") - lua-ts--nested-function-block-matcher - lua-ts--nested-function-block-include-matcher) - parent lua-ts-indent-offset) - ((and (n-p-gp "block" "function_definition" "arguments") - lua-ts--nested-function-argument-matcher) - parent lua-ts-indent-offset) - ((match "function_definition" "parenthesized_expression") - standalone-parent lua-ts-indent-offset) - ((node-is "block") standalone-parent lua-ts-indent-offset) - ((parent-is "block") parent 0) - ((and (node-is "end") lua-ts--end-line-matcher) - standalone-parent lua-ts--end-indent-offset) - ((match "end" "function_declaration") parent 0) - ((and (n-p-gp "end" "function_definition" "parenthesized_expression") - lua-ts--nested-function-end-argument-matcher) - parent 0) - ((and (n-p-gp "end" "function_definition" "parenthesized_expression") - lua-ts--nested-function-block-matcher - lua-ts--nested-function-end-matcher - lua-ts--nested-function-last-function-matcher) - parent 0) - ((and (n-p-gp "end" "function_definition" "arguments") - lua-ts--top-level-function-call-matcher) - standalone-parent 0) - ((n-p-gp "end" "function_definition" "arguments") parent 0) - ((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) + + ;; Handle multi-line concatenation and continuation. + ((or (n-p-gp "expression_list" "assignment_statement" "variable_declaration") + (and (parent-is "binary_expression") + lua-ts--variable-declaration-continuation)) lua-ts--variable-declaration-continuation-anchor lua-ts-indent-offset) + ;; `lua-ts-indent-continuation-lines' is non-nil. ((and (lambda (&rest _) lua-ts-indent-continuation-lines) (parent-is "binary_expression")) standalone-parent lua-ts-indent-offset) + ;; `lua-ts-indent-continuation-lines' is nil. ((parent-is "binary_expression") standalone-parent 0) + + ;; Handle immediately invoked function expressions. + ((or (n-p-gp "block" "function_definition" "parenthesized_expression") + (n-p-gp "block" "function_definition" "arguments")) + parent lua-ts-indent-offset) + ((or (n-p-gp "end" "function_definition" "parenthesized_expression") + (n-p-gp "end" "function_definition" "arguments")) + parent 0) + + ;; Handle basic indentation. + ((or (node-is "do") + (node-is "then") + (node-is "elseif_statement") + (node-is "else_statement") + (node-is "until") + (node-is "end") + (node-is ")")) + standalone-parent 0) + ((or (parent-is "function_declaration") (parent-is "function_definition") (parent-is "do_statement") @@ -377,10 +354,19 @@ values of OVERRIDE." (parent-is "while_statement") (parent-is "if_statement") (parent-is "else_statement") - (parent-is "elseif_statement")) + (parent-is "elseif_statement") + ;; `c-ts-common-baseline-indent-rule' will handle further + ;; siblings after the first one has been properly indented. + ;; The opening bracket occupies index 0. + (match nil "arguments" nil 1 1) + (match nil "parameters" nil 1 1) + (match "field" "table_constructor" nil 1 1)) standalone-parent lua-ts-indent-offset) + + ((parent-is "block") parent 0) ((parent-is "chunk") column-0 0) - ((parent-is "ERROR") no-indent 0)))) + ((parent-is "ERROR") no-indent 0) + c-ts-common-baseline-indent-rule))) (defun lua-ts--end-line-matcher (&rest _) "Matches if there is more than one `end' on the current line." @@ -394,27 +380,11 @@ values of OVERRIDE." "Count the number of `end's on the current line." (count-matches "end" (line-beginning-position) (line-end-position))) -(defun lua-ts--first-child-matcher (node &rest _) - "Matches if NODE is the first among its siblings." - (= (treesit-node-index node) 1)) - -(defun lua-ts--function-definition-p (node) - "Return t if NODE is a function_definition." - (equal "function_definition" (treesit-node-type node))) - (defun lua-ts--g-parent (node) "Return the grand-parent of NODE." (let ((parent (treesit-node-parent node))) (treesit-node-parent parent))) -(defun lua-ts--g-g-parent (node) - "Return the great-grand-parent of NODE." - (treesit-node-parent (lua-ts--g-parent node))) - -(defun lua-ts--g-g-g-parent (node) - "Return the great-great-grand-parent of NODE." - (treesit-node-parent (lua-ts--g-g-parent node))) - (defun lua-ts--multi-arg-function-call-matcher (_n parent &rest _) "Matches if PARENT has multiple arguments." (> (treesit-node-child-count (treesit-node-parent parent)) 3)) @@ -425,86 +395,18 @@ values of OVERRIDE." (last (1- (treesit-node-child-count g-parent t)))) (treesit-node-eq parent (seq-elt (treesit-node-children g-parent t) last)))) -(defun lua-ts--nested-function-argument-matcher (node &rest _) - "Matches if NODE is in a nested function argument." - (save-excursion - (goto-char (treesit-node-start node)) - (treesit-beginning-of-defun) - (backward-char 2) - (and (not (looking-at ")(")) - (not (equal "chunk" - (treesit-node-type - (lua-ts--g-parent (treesit-node-at (point))))))))) - -(defun lua-ts--nested-function-block-matcher (node &rest _) - "Matches if NODE is in a nested function block." - (let* ((g-g-g-parent (lua-ts--g-g-g-parent node)) - (g-g-g-type (treesit-node-type g-g-g-parent))) - (not (equal g-g-g-type "chunk")))) - -(defun lua-ts--nested-function-block-include-matcher (node _p bol &rest _) - "Matches if NODE's child at BOL is not another block." - (let* ((child (treesit-node-first-child-for-pos node bol)) - (child-type (treesit-node-type child)) - (g-g-g-type (treesit-node-type (lua-ts--g-g-g-parent node)))) - (or (equal child-type "assignment_statement") - (and (equal child-type "return_statement") - (or (equal g-g-g-type "arguments") - (and (equal g-g-g-type "expression_list") - (not (treesit-search-subtree child "function_call")))))))) - -(defun lua-ts--nested-function-end-matcher (node &rest _) - "Matches if NODE is the `end' of a nested function." - (save-excursion - (goto-char (treesit-node-start node)) - (treesit-beginning-of-defun) - (looking-at "function[[:space:]]*"))) - -(defun lua-ts--nested-function-end-argument-matcher (node &rest _) - "Matches if great-great-grandparent of NODE is arguments." - (equal "arguments" (treesit-node-type (lua-ts--g-g-g-parent node)))) - -(defun lua-ts--nested-function-last-function-matcher (_n parent &rest _) - "Matches if PARENT is the last nested function." - (let ((sparse-tree - (treesit-induce-sparse-tree parent #'lua-ts--function-definition-p))) - (= 1 (length (cadr sparse-tree))))) - -(defun lua-ts--comment-first-sibling-matcher (node &rest _) - "Matches NODE if its previous sibling is a comment." - (let ((sibling (treesit-node-prev-sibling node))) - (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." - (let* ((g-g-p (lua-ts--g-g-parent node)) - (g-g-g-p (lua-ts--g-g-g-parent node))) - (and (equal "function_call" (treesit-node-type g-g-p)) - (equal "chunk" (treesit-node-type g-g-g-p))))) - -(defun lua-ts--first-real-sibling-anchor (_n parent _) - "Return the start position of the first non-comment child of PARENT." - (treesit-node-start - (seq-first - (seq-filter - (lambda (n) (not (equal "comment" (treesit-node-type n)))) - (treesit-node-children parent t))))) - (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))))) + (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)) + (when (looking-back (rx bol (* whitespace)) (line-beginning-position)) (point)))) (defun lua-ts--multi-line-comment-start (node &rest _) @@ -783,6 +685,8 @@ Calls REPORT-FN directly." variable))) ;; Indent. + (setq-local c-ts-common-indent-offset 'lua-ts-indent-offset) + (setq-local c-ts-common-list-indent-style 'simple) (setq-local treesit-simple-indent-rules lua-ts--simple-indent-rules) ;; Navigation. diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index b0ece4cc261..575e0e2cbf0 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -1,7 +1,7 @@ Code: (lambda () - (setq indent-tabs-mode nil) (setq lua-ts-indent-offset 2) + (setq indent-tabs-mode nil) (lua-ts-mode) (indent-region (point-min) (point-max))) @@ -15,24 +15,51 @@ print(1) print(2) =-=-= -Name: Function Indent +Name: Function Indent 1 =-= function f1(n) print(n) return n + 1 end +=-= +function f1(n) + print(n) + return n + 1 +end +=-=-= + +Name: Function Indent 2 +=-= local function f2(n) print(n) return n * 2 end +=-= +local function f2(n) + print(n) + return n * 2 +end +=-=-= +Name: Function Indent 3 + +=-= local f3 = function(n) print(n) return n / 3 end +=-= +local f3 = function(n) + print(n) + return n / 3 +end +=-=-= +Name: Function Indent 4 + +=-= function f4(...) local f = function (...) if ok @@ -42,7 +69,21 @@ end end return f end +=-= +function f4(...) + local f = function (...) + if ok + then print(1) + else print(0) + end + end + return f +end +=-=-= + +Name: Function Indent 5 +=-= function f5(...) local f = function (...) if ok @@ -54,51 +95,7 @@ end end return f end - -function f6(...) -local f = function (...) -if ok then -print(1) -else -print(0) -end -end -return f -end - -f6(function() -print'ok' -end) - -;(function () - return true - end)() =-= -function f1(n) - print(n) - return n + 1 -end - -local function f2(n) - print(n) - return n * 2 -end - -local f3 = function(n) - print(n) - return n / 3 -end - -function f4(...) - local f = function (...) - if ok - then print(1) - else print(0) - end - end - return f -end - function f5(...) local f = function (...) if ok @@ -110,7 +107,22 @@ function f5(...) end return f end +=-=-= + +Name: Function Indent 6 +=-= +function f6(...) +local f = function (...) +if ok then +print(1) +else +print(0) +end +end +return f +end +=-= function f6(...) local f = function (...) if ok then @@ -121,17 +133,33 @@ function f6(...) end return f end +=-=-= + +Name: Function Indent 7 -f6(function() - print'ok' +=-= +f7(function() +print'ok' end) +=-= +f7(function() + print'ok' + end) +=-=-= + +Name: Function Indent 8 +=-= ;(function () - return true -end)() + return true + end)() +=-= +;(function () + return true + end)() =-=-= -Name: Conditional Indent +Name: Conditional Indent 1 =-= if true then @@ -144,7 +172,22 @@ else print(nil) return 0 end +=-= +if true then + print(true) + return 1 +elseif false then + print(false) + return -1 +else + print(nil) + return 0 +end +=-=-= +Name: Conditional Indent 2 + +=-= if true then print(true) @@ -157,25 +200,7 @@ if true print(nil) return 0 end - -if true - then return 1 - elseif false - then return -1 - else return 0 -end =-= -if true then - print(true) - return 1 -elseif false then - print(false) - return -1 -else - print(nil) - return 0 -end - if true then print(true) @@ -188,7 +213,18 @@ else print(nil) return 0 end +=-=-= +Name: Conditional Indent 3 + +=-= +if true + then return 1 + elseif false + then return -1 + else return 0 +end +=-= if true then return 1 elseif false @@ -197,39 +233,93 @@ else return 0 end =-=-= -Name: Loop Indent +Name: Loop Indent 1 =-= for k,v in pairs({}) do print(k) print(v) end +=-= +for k,v in pairs({}) do + print(k) + print(v) +end +=-=-= +Name: Loop Indent 2 + +=-= for i=1,10 do print(i) end +=-= +for i=1,10 +do print(i) +end +=-=-= +Name: Loop Indent 3 + +=-= while n < 10 do n = n + 1 print(n) end +=-= +while n < 10 do + n = n + 1 + print(n) +end +=-=-= + +Name: Loop Indent 4 +=-= while n < 10 do n = n + 1 print(n) end +=-= +while n < 10 +do + n = n + 1 + print(n) +end +=-=-= + +Name: Loop Indent 5 +=-= for i=0,9 do repeat n = n+1 until n > 99 end +=-= +for i=0,9 do + repeat n = n+1 + until n > 99 +end +=-=-= + +Name: Loop Indent 6 +=-= repeat z = z * 2 print(z) until z > 12 +=-= +repeat + z = z * 2 + print(z) +until z > 12 +=-=-= + +Name: Loop Indent 7 +=-= for i,x in ipairs(t) do while i < 9 do @@ -243,42 +333,7 @@ until z > 12 end print(t[i]) end - -do -local a = b -print(a + 1) -end =-= -for k,v in pairs({}) do - print(k) - print(v) -end - -for i=1,10 -do print(i) -end - -while n < 10 do - n = n + 1 - print(n) -end - -while n < 10 -do - n = n + 1 - print(n) -end - -for i=0,9 do - repeat n = n+1 - until n > 99 -end - -repeat - z = z * 2 - print(z) -until z > 12 - for i,x in ipairs(t) do while i < 9 do @@ -292,37 +347,54 @@ for i,x in ipairs(t) do end print(t[i]) end +=-=-= + +Name: Loop Indent 8 +=-= +do +local a = b +print(a + 1) +end +=-= do local a = b print(a + 1) end =-=-= -Name: Bracket Indent +Name: Bracket Indent 1 =-= fn( ) - -tb={ - } =-= fn( ) +=-=-= +Name: Bracket Indent 2 + +=-= +tb={ + } +=-= tb={ } =-=-= -Name: Multi-line String Indent +Name: Multi-line String Indent 1 =-= local s = [[ Multi-line string content ]] +=-=-= +Name: Multi-line String Indent 2 + +=-= function f() local str = [[ multi-line @@ -331,11 +403,6 @@ function f() return true end =-= -local s = [[ - Multi-line - string content - ]] - function f() local str = [[ multi-line @@ -345,31 +412,18 @@ function f() end =-=-= -Name: Multi-line Comment Indent +Name: Multi-line Comment Indent 1 =-= --[[ Multi-line comment content ]] +=-=-= -function f() ---[[ -multi-line - comment - ]] - return true -end +Name: Multi-line Comment Indent 2 - --[[ -Long comment. - ]] =-= ---[[ - Multi-line - comment content - ]] - function f() --[[ multi-line @@ -377,143 +431,191 @@ multi-line ]] return true end +=-=-= + +Name: Multi-line Comment Indent 3 +=-= --[[ Long comment. ]] =-=-= -Name: Comment Indent +Name: Comment Indent 1 =-= local fn1 = function (a, b) -- comment return a + b end +=-= +local fn1 = function (a, b) + -- comment + return a + b +end +=-=-= + +Name: Comment Indent 2 +=-= 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 - -=-= - h( - "string", - 1000 - ) - -local p = h( -"string", - 1000 -) - -fn(1, -2, - 3) - -fn( 1, 2, -3, 4 ) - -f({ -x = 1, -y = 2, -z = 3, -}) - -f({ x = 1, -y = 2, -z = 3, }) - -Test({ -a=1 -}) +Name: Comment Indent 3 -Test({ -a = 1, -b = 2, -}, -nil) +=-= +local tb9 = { one = 1, +-- comment + two = 2 } +=-= +local tb9 = { one = 1, + -- comment + two = 2 } +=-=-= -Test(nil, { - a = 1, - b = 2, - }) +Name: Argument Indent 1 -fn( -- comment - 1, - 2) +=-= + h( + "string", + 1000 + ) =-= h( "string", 1000 ) +=-=-= +Name: Argument Indent 2 + +=-= +local p = h( +"string", + 1000 +) +=-= local p = h( "string", 1000 ) +=-=-= +Name: Argument Indent 3 + +=-= +fn(1, +2, + 3) +=-= fn(1, 2, 3) +=-=-= + +Name: Argument Indent 4 +=-= +fn( 1, 2, +3, 4 ) +=-= fn( 1, 2, 3, 4 ) +=-=-= + +Name: Argument Indent 5 +=-= +f({ +x = 1, +y = 2, +z = 3, +}) +=-= f({ x = 1, y = 2, z = 3, }) +=-=-= +Name: Argument Indent 6 + +=-= +f({ x = 1, +y = 2, +z = 3, }) +=-= f({ x = 1, y = 2, z = 3, }) +=-=-= + +Name: Argument Indent 7 +=-= +Test({ +a=1 +}) +=-= Test({ a=1 }) +=-=-= +Name: Argument Indent 8 + +=-= +Test({ +a = 1, +b = 2, +}, +nil) +=-= Test({ a = 1, b = 2, }, nil) +=-=-= + +Name: Argument Indent 9 +=-= +Test(nil, { + a = 1, + b = 2, + }) +=-= Test(nil, { a = 1, b = 2, }) +=-=-= + +Name: Argument Indent 10 +=-= +fn( -- comment + 1, + 2) +=-= fn( -- comment 1, 2) =-=-= -Name: Parameter Indent +Name: Parameter Indent 1 =-= function f1( @@ -522,19 +624,6 @@ b ) print(a,b) end - -local function f2(a, - b) -print(a,b) -end - -local f3 = function( a, b, - c, d ) -print(a,b,c,d) -end - -local f4 = function(-- comment -a, b, c) =-= function f1( a, @@ -542,22 +631,47 @@ function f1( ) print(a,b) end +=-=-= + +Name: Parameter Indent 2 +=-= +local function f2(a, + b) +print(a,b) +end +=-= local function f2(a, b) print(a,b) end +=-=-= + +Name: Parameter Indent 3 +=-= +local f3 = function( a, b, + c, d ) +print(a,b,c,d) +end +=-= local f3 = function( a, b, c, d ) print(a,b,c,d) end +=-=-= + +Name: Parameter Indent 4 +=-= +local f4 = function(-- comment +a, b, c) +=-= local f4 = function(-- comment a, b, c) =-=-= -Name: Table Indent +Name: Table Indent 1 =-= local Other = { @@ -574,16 +688,6 @@ local Other = { left={Goto=true}, right={Goto=true}} } - -local Other = { -a = 1, - b = 2, - c = 3, -} - -local a = { -- hello world! - b = 10 -} =-= local Other = { First={up={Step=true,Jump=true}, @@ -599,31 +703,77 @@ local Other = { left={Goto=true}, right={Goto=true}} } +=-=-= + +Name: Table Indent 2 +=-= +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= local Other = { a = 1, b = 2, c = 3, } +=-=-= +Name: Table Indent 3 + +=-= +local a = { -- hello world! + b = 10 +} +=-= local a = { -- hello world! b = 10 } =-=-= -Name: Continuation Indent +Name: Continuation Indent 1 =-= local very_long_variable_name = "ok".. "ok" +=-= +local very_long_variable_name = + "ok".. + "ok" +=-=-= + +Name: Continuation Indent 2 + +=-= local n = a + b * c / 1 +=-= +local n = a + + b * + c / + 1 +=-=-= + +Name: Continuation Indent 3 + +=-= local x = "A".. "B" .."C" +=-= +local x = "A".. + "B" + .."C" +=-=-= + +Name: Continuation Indent 4 + +=-= if a and b and c then @@ -638,16 +788,6 @@ elseif a 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 @@ -665,12 +805,12 @@ end Code: (lambda () - (setq indent-tabs-mode nil) (setq lua-ts-indent-offset 4) (lua-ts-mode) + (setq indent-tabs-mode nil) (indent-region (point-min) (point-max))) -Name: End Indent +Name: End Indent 1 =-= function f(x) @@ -682,14 +822,6 @@ function f(x) end end end end return {x,y} or {math.random(),math.random()} end - -for y=1,x.y do - for x=1,x.z do - if x.y and x.z then - if y <= x then - y = y + 1 - end - end end end =-= function f(x) for y=1,x.y do @@ -700,7 +832,19 @@ function f(x) end end end end return {x,y} or {math.random(),math.random()} end +=-=-= +Name: End Indent 2 + +=-= +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end + end end end +=-= for y=1,x.y do for x=1,x.z do if x.y and x.z then @@ -710,30 +854,78 @@ for y=1,x.y do end end end =-=-= -Name: Nested Function Indent +Name: Nested Function Indent 1 +=-= +function a(...) +return (function (x) +return x +end)(foo(...)) +end =-= function a(...) return (function (x) return x end)(foo(...)) end +=-=-= +Name: Nested Function Indent 2 + +=-= +function b(n) +local x = 1 +return function (i) +return function (...) +return (function (n, ...) +return function (f, ...) +return (function (...) +if ... and x < 9 then +x = x + 1 +return ... +end end)(n(f, ...)) +end, ... +end)(i(...)) +end end end +=-= function b(n) local x = 1 return function (i) return function (...) return (function (n, ...) - return function (f, ...) - return (function (...) - if ... and x < 9 then - x = x + 1 - return ... - end end)(n(f, ...)) - end, ... - end)(i(...)) + return function (f, ...) + return (function (...) + if ... and x < 9 then + x = x + 1 + return ... + end end)(n(f, ...)) + end, ... + end)(i(...)) end end end +=-=-= +Name: Nested Function Indent 3 + +=-= +function c(f) +local f1 = function (...) +if nil ~= ... then +return f(...) +end +end +return function (i) +return function (...) +local fn = function (n, ...) +local x = function (f, ...) +return f1(n(f, ...)) +end +return x +end +return fn(i(...)) +end +end +end +=-= function c(f) local f1 = function (...) if nil ~= ... then @@ -752,7 +944,29 @@ function c(f) end end end +=-=-= +Name: Nested Function Indent 4 + +=-= +function d(f) +local f1 = function (c, f, ...) +if ... then +if f(...) then +return ... +else +return c(f, ...) +end end end +return function (i) +return function (...) +return (function (n, ...) +local function j (f, ...) +return f1(j, f, n(f, ...)) +end +return j, ... +end)(i(...)) +end end end +=-= function d(f) local f1 = function (c, f, ...) if ... then @@ -764,13 +978,57 @@ function d(f) return function (i) return function (...) return (function (n, ...) - local function j (f, ...) - return f1(j, f, n(f, ...)) - end - return j, ... - end)(i(...)) + local function j (f, ...) + return f1(j, f, n(f, ...)) + end + return j, ... + end)(i(...)) end end end +=-=-= +Name: Nested Function Indent 5 + +=-= +function e (n, t) +return function (i) +return function (...) +return ( +function (n, ...) +local x, y, z = 0, {} +return (function (f, ...) +return (function (i, ...) return i(i, ...) end)( +function (i, ...) +return f(function (x, ...) +return i(i, ...)(x, ...) +end, ...) +end) +end)(function (j) +return function(f, ...) +return (function (c, f, ...) +if ... then +if n+1 == x then +local y1, x1 = y, x +y, x = {}, 0 +return (function (...) +z = ... +return ... +end)(t(y1-1, x1-1, ...)) +else +x = x - 1 +return c(f, +(function (...) +z = ... +return ... +end)(t(y, x, ...))) +end +elseif x ~= 0 then +x = 0 +return z, y +end end)(j, f, n(f, ...)) +end end), ... +end)(i(...)) +end end end +=-= function e (n, t) return function (i) return function (...) @@ -778,46 +1036,46 @@ function e (n, t) function (n, ...) local x, y, z = 0, {} return (function (f, ...) - return (function (i, ...) return i(i, ...) end)( - function (i, ...) - return f(function (x, ...) - return i(i, ...)(x, ...) - end, ...) - end) - end)(function (j) - return function(f, ...) - return (function (c, f, ...) - if ... then - if n+1 == x then - local y1, x1 = y, x - y, x = {}, 0 - return (function (...) - z = ... - return ... - end)(t(y1-1, x1-1, ...)) - else - x = x - 1 - return c(f, - (function (...) - z = ... - return ... - end)(t(y, x, ...))) - end - elseif x ~= 0 then - x = 0 - return z, y - end end)(j, f, n(f, ...)) - end end), ... + return (function (i, ...) return i(i, ...) end)( + function (i, ...) + return f(function (x, ...) + return i(i, ...)(x, ...) + end, ...) + end) + end)(function (j) + return function(f, ...) + return (function (c, f, ...) + if ... then + if n+1 == x then + local y1, x1 = y, x + y, x = {}, 0 + return (function (...) + z = ... + return ... + end)(t(y1-1, x1-1, ...)) + else + x = x - 1 + return c(f, + (function (...) + z = ... + return ... + end)(t(y, x, ...))) + end + elseif x ~= 0 then + x = 0 + return z, y + end end)(j, f, n(f, ...)) + end end), ... 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) + (setq indent-tabs-mode nil) (indent-region (point-min) (point-max))) Name: Unaligned Continuation Indent