From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 06 17:02:51 2024 Received: (at submit) by debbugs.gnu.org; 6 Jan 2024 22:02:51 +0000 Received: from localhost ([127.0.0.1]:60370 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMEkl-0002yD-7x for submit@debbugs.gnu.org; Sat, 06 Jan 2024 17:02:51 -0500 Received: from lists.gnu.org ([2001:470:142::17]:59278) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMEkh-0002xz-Sl for submit@debbugs.gnu.org; Sat, 06 Jan 2024 17:02:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMEkX-0007kj-5H for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 17:02:37 -0500 Received: from out-174.mta1.migadu.com ([2001:41d0:203:375::ae]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMEkV-0003to-57 for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 17:02:36 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1704578550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=7z4ogKJR2/NscYdPDuPUOdH9uCHo5jKMFRvfQ4w8Z7o=; b=niqgmY2RyPGSm+8Zo5ee4mRfssPMIOAWoeOgrWmaYHmf/0VW7cq7kU5SVguV5R6L7T/IQU m3DWFpaehKxlaWyXnS24gvZzWqNcZiLJfq/VfuXKzUVAvzb2UuvfvgTbBcB4QOAGfQeB/L 2ea9Fnv2ywKtzJB75TaPIFM7VL3fJZE= From: john muhl To: bug-gnu-emacs@gnu.org Subject: [PATCH] Support indented continuation lines in lua-ts-mode Date: Sat, 06 Jan 2024 12:56:17 -0600 Message-ID: <8734vaglxp.fsf@pub.pink> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:203:375::ae; envelope-from=jm@pub.pink; helo=out-174.mta1.migadu.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add rules for indenting multi-line variables and if/elseif statements, e.g.: local very_long_variable_name = "ABC".. "XYZ" local v = 123 * 456 + 789 if a and b or c then print(1) elseif b and c or a then print(0) end Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.9 SPF_FAIL SPF: sender does not match SPF record (fail) [SPF failed: Please see http://www.openspf.org/Why?s=mfrom; id=jm%40pub.pink; ip=2001%3A470%3A142%3A%3A17; r=debbugs.gnu.org] 1.1 DATE_IN_PAST_03_06 Date: is 3 to 6 hours before Received: date -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Add rules for indenting multi-line variables and if/elseif statements, e.g.: local very_long_variable_name = "ABC".. "XYZ" local v = 123 * 456 + 789 if a and b or c then print(1) elseif b and c or a then print(0) end The lua-ts-indent-continuation-lines option can be set to nil to keep if statements flush left: if a and b or c then print(1) elseif b and c or a then print(0) end The option controlling this behavior in the EmmyLua code formatter does not affect multi-line variables so neither does lua-ts-indent-continuation-lines. From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 06 17:39:55 2024 Received: (at 68297) by debbugs.gnu.org; 6 Jan 2024 22:39:55 +0000 Received: from localhost ([127.0.0.1]:60385 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMFKd-0000er-DN for submit@debbugs.gnu.org; Sat, 06 Jan 2024 17:39:55 -0500 Received: from out-181.mta0.migadu.com ([91.218.175.181]:41756) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMFKZ-0000ed-RP for 68297@debbugs.gnu.org; Sat, 06 Jan 2024 17:39:53 -0500 References: <8734vaglxp.fsf@pub.pink> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1704580785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rsSPOn76l+NDNokuavJzIhE0I82hAwGyQppZscB4AmA=; b=Rn59eFYvke6nyENjeBynru6s//oj+xbJKFcBDeGCR+goHZODl9zgTsGCb4O1iLZRcPkE5C aEJZZ3a+/p/IoJVFAi1nCwNRoA4dQEMcZ9KCn14m1NRqLvVFrmOCPU2ZJ5A/XDRgL7hQst 7nuDZ1m3zPfYDXCSI4wGmyjfII+z5UY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: 68297@debbugs.gnu.org Subject: Re: bug#68297: [PATCH] Support indented continuation lines in lua-ts-mode Date: Sat, 06 Jan 2024 16:37:55 -0600 In-reply-to: <8734vaglxp.fsf@pub.pink> Message-ID: <87h6jqf5n6.fsf@pub.pink> MIME-Version: 1.0 Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Support-indented-continuation-lines-in-lua-ts-mode.patch X-Migadu-Flow: FLOW_OUT X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 68297 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) >From 8e73025f048bcd5c405a19fc090f7c58cb728c5a Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 6 Jan 2024 09:36:33 -0600 Subject: [PATCH] Support indented continuation lines in lua-ts-mode * lisp/progmodes/lua-ts-mode.el (lua-ts--simple-indent-rules): Add a rule to indent multi-line assignments and if statements. (lua-ts-indent-continuation-lines): New user option. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Add tests. (bug#68279) --- lisp/progmodes/lua-ts-mode.el | 47 ++++++++++++ .../lua-ts-mode-resources/indent.erts | 76 +++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index e9ffb47cdb2..63a33a14ed7 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -150,6 +150,28 @@ lua-ts-align-params-and-props :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" @@ -362,6 +384,17 @@ lua-ts--simple-indent-rules ((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") @@ -448,6 +481,20 @@ lua-ts--nested-function-last-function-matcher (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))) + (line-beginning-position))) + (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 5e6ce7935f8..2e7384cac88 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -529,6 +529,46 @@ local Other = { } =-=-= +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 +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 +elseif a + or b + or c then +end +=-=-= + Code: (lambda () (setq indent-tabs-mode nil) @@ -711,3 +751,39 @@ tbl = {1,2, 3,4, 5,6} =-=-= + +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 +elseif a + or b + or c then +end +=-= +local n = a + + b * + c / + 1 +if a +and b +and c then +elseif a +or b +or c then +end +=-=-= -- 2.41.0 From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 06 18:00:59 2024 Received: (at 68297) by debbugs.gnu.org; 6 Jan 2024 23:00:59 +0000 Received: from localhost ([127.0.0.1]:60389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMFf0-0005nD-G4 for submit@debbugs.gnu.org; Sat, 06 Jan 2024 18:00:58 -0500 Received: from out-185.mta0.migadu.com ([2001:41d0:1004:224b::b9]:58331) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMFey-0005h0-Au for 68297@debbugs.gnu.org; Sat, 06 Jan 2024 18:00:57 -0500 References: <8734vaglxp.fsf@pub.pink> <87h6jqf5n6.fsf@pub.pink> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1704582049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=219uXCOIHadRV/wxJAZp7ech0JKGno9n3wWLRk28ogM=; b=O1+Pc7DvyKhD2flM5jHuMO1sW9kOCPZOmEi7vpzgRzK04cMDGI/+3Jjwb5l/W8URFzEdRF iHQE3V7YXX6BMkOpEEQwmfJsO+/uPRIkaSX0InRnmE+RLLGvPb5NgGOzjRvAiIN4AbvJP2 zfmGfA+lTLW96Lo1h44wv2vPj6wO40c= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: 68297@debbugs.gnu.org Subject: Re: bug#68297: [PATCH] Support indented continuation lines in lua-ts-mode Date: Sat, 06 Jan 2024 16:57:57 -0600 In-reply-to: <87h6jqf5n6.fsf@pub.pink> Message-ID: <875y06f4o1.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 68297 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Ignore the previous. I accidentally made it from the wrong branch. This one should apply cleanly. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Support-indented-continuation-lines-in-lua-ts-mode.patch >From 86b5bba1d3c2850151ff280be6df458d898cdf11 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 6 Jan 2024 09:36:33 -0600 Subject: [PATCH] Support indented continuation lines in lua-ts-mode * lisp/progmodes/lua-ts-mode.el (lua-ts--simple-indent-rules): Add a rule to indent multi-line assignments and if statements. (lua-ts-indent-continuation-lines): New user option. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Add tests. (bug#68279) --- lisp/progmodes/lua-ts-mode.el | 47 ++++++++++++ .../lua-ts-mode-resources/indent.erts | 76 +++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 3b600f59521..714fab8e852 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -122,6 +122,28 @@ lua-ts-inferior-history :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" @@ -329,6 +351,17 @@ lua-ts--simple-indent-rules ((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") @@ -415,6 +448,20 @@ lua-ts--nested-function-last-function-matcher (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))) + (line-beginning-position))) + (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 9797467bbe5..a535c46f871 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -529,6 +529,46 @@ local Other = { } =-=-= +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 +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 +elseif a + or b + or c then +end +=-=-= + Code: (lambda () (setq indent-tabs-mode nil) @@ -677,3 +717,39 @@ function e (n, t) 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 +elseif a + or b + or c then +end +=-= +local n = a + + b * + c / + 1 +if a +and b +and c then +elseif a +or b +or c then +end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 06 19:43:42 2024 Received: (at submit) by debbugs.gnu.org; 7 Jan 2024 00:43:42 +0000 Received: from localhost ([127.0.0.1]:60445 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMHGQ-0007jN-1f for submit@debbugs.gnu.org; Sat, 06 Jan 2024 19:43:42 -0500 Received: from lists.gnu.org ([2001:470:142::17]:60914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rMHGN-0007jA-BR for submit@debbugs.gnu.org; Sat, 06 Jan 2024 19:43:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMHGC-0004EA-F6 for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 19:43:28 -0500 Received: from out-185.mta0.migadu.com ([2001:41d0:1004:224b::b9]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMHG9-0001PL-O8 for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 19:43:28 -0500 References: <8734vaglxp.fsf@pub.pink> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1704588202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9pj1aoIM7DLZC0S5sHM7PTU8rYMdv/g0HyBNpSL0jUs=; b=dA45zx0xvRvogtcn05h9SYttbJQKY8YWrFIwcfP9dKyT2NzvNVHWLzRpPM3iYyjIR/9GKI TRZ/9hn8jMdCdvAOYbfCJI5J9gQGvd1TvVg8ExCrzXj6nao9h0nwtDgwJnfyQnvmumajjZ 7p7ez+EWHWVfh6Dyj216f0B5QlAXm2M= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: john muhl Subject: Re: [PATCH] Support indented continuation lines in lua-ts-mode Date: Sat, 06 Jan 2024 18:39:30 -0600 In-reply-to: <8734vaglxp.fsf@pub.pink> Message-ID: <87o7dydlcp.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:1004:224b::b9; envelope-from=jm@pub.pink; helo=out-185.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit Cc: bug-gnu-emacs@gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) --=-=-= Content-Type: text/plain ...and now I see that only handled top-level statements. This one works with nested ifs and variables too. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Support-indented-continuation-lines-in-lua-ts-mode.patch >From ed76e90d51924f9c457e8c4c90a535be01052777 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 6 Jan 2024 09:36:33 -0600 Subject: [PATCH] Support indented continuation lines in lua-ts-mode * lisp/progmodes/lua-ts-mode.el (lua-ts--simple-indent-rules): Add a rule to indent multi-line assignments and if statements. (lua-ts-indent-continuation-lines): New user option. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Add tests. (bug#68279) --- lisp/progmodes/lua-ts-mode.el | 49 ++++++++ .../lua-ts-mode-resources/indent.erts | 106 ++++++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 3b600f59521..05a3ff6d7c6 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -122,6 +122,28 @@ lua-ts-inferior-history :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" @@ -329,6 +351,17 @@ lua-ts--simple-indent-rules ((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") @@ -415,6 +448,22 @@ lua-ts--nested-function-last-function-matcher (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) diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 9797467bbe5..48184160b4d 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -529,6 +529,58 @@ local Other = { } =-=-= +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) @@ -677,3 +729,57 @@ function e (n, t) 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 +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 11 15:49:30 2024 Received: (at control) by debbugs.gnu.org; 11 Jan 2024 20:49:30 +0000 Received: from localhost ([127.0.0.1]:34089 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO1zV-0005hB-Q0 for submit@debbugs.gnu.org; Thu, 11 Jan 2024 15:49:30 -0500 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]:59412) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO1zU-0005gw-Ep for control@debbugs.gnu.org; Thu, 11 Jan 2024 15:49:28 -0500 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2cd81b09e83so19080951fa.2 for ; Thu, 11 Jan 2024 12:49:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705006165; x=1705610965; darn=debbugs.gnu.org; h=to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=tY7hzhEjCfU2AXuPjfS3uuOQ7J7ygAV+k+rDB9nDF3E=; b=iPs613GXMJaic/QcLArxHOGXkhg2XO/lwWjEOF9CtmBSrVf/DikumvJajJd9tUAFZ+ qOUht4qkRaQT8A87VvTJijq7XGPIuqLVhRC169PlTRMs5gOXORQabgrUrwIXJKJBFLGV +m664TiIlTU08Y5lbRTTo6b+1yb3evfvtQAfP8M+Fm/CmqOw9z+Z+DvS8g9YAeAVIGIB FlFeArwVwzHzzLVVi1Y6H0ekXVnD1IVJtxaa0wZypaI8coiXHxp96uam2pT5JrNAYkPl xYts9jqvBvS71W5J6qPmNpuQcxpsrD3/Ehdp5543DvK3kanttzDsWYDm02a/uXFtL7/i Uw3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705006165; x=1705610965; h=to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tY7hzhEjCfU2AXuPjfS3uuOQ7J7ygAV+k+rDB9nDF3E=; b=KNJGkYZW08zGQ4dLum+oJMhhgPu1FfhnoIXcpbNBoLdJkTjnJy0haCyzRFHEA+RCE3 p6FLDhkcu5Y4bvv0IWfDoUgq6d9qDMdZVMlxI5CSiCbw38VhAIjVif4xjm4Gf0YtpCOy KyjKjhslOScos3KNxmoBhfUmSVpjw9R01uyPCburJySELzt/F/rmMhGGdioeUQYDFe8g wtwFDT9LBMVuEfDxW1PSCyLjs2IAGzJlXGTikih2ztwvF5SK1+DbP0aKFU+BY1STEIuM h3Gq1149iEBNXfuxZpC6muG9mXDm63ZWcisSdPRHXLG11KLSfBfbCs6DyMCsGFkt6Q48 UU+A== X-Gm-Message-State: AOJu0YwxDprUqEhk5SmoGS2zHgA9XZh3PWdAMeziW/xzJ2WC5aM0KWGD wTx4fxyU1amAJdyFynZsu7vFmyMPKWO+9vbG1mD2YXLHMik= X-Google-Smtp-Source: AGHT+IF01kb1Ds6vrZdRvOYubJnmOkuSrGqGycOA2KiT+wq/t+9LmarhcoDXHNoHxtyinL2zdEw2gO+9aRVekCQczU4= X-Received: by 2002:a2e:9057:0:b0:2cc:9a33:b001 with SMTP id n23-20020a2e9057000000b002cc9a33b001mr86554ljg.129.1705006165063; Thu, 11 Jan 2024 12:49:25 -0800 (PST) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 11 Jan 2024 12:49:24 -0800 From: Stefan Kangas MIME-Version: 1.0 Date: Thu, 11 Jan 2024 12:49:24 -0800 Message-ID: Subject: control message for bug #68297 To: control@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) severity 68297 wishlist quit From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 11 15:52:30 2024 Received: (at 68297-done) by debbugs.gnu.org; 11 Jan 2024 20:52:30 +0000 Received: from localhost ([127.0.0.1]:34098 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO22Q-0005mK-9R for submit@debbugs.gnu.org; Thu, 11 Jan 2024 15:52:30 -0500 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]:61718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO22N-0005m4-FE for 68297-done@debbugs.gnu.org; Thu, 11 Jan 2024 15:52:28 -0500 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2cd928a1d58so6575131fa.3 for <68297-done@debbugs.gnu.org>; Thu, 11 Jan 2024 12:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705006344; x=1705611144; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=w2DckAmZMDW/xUfMFPRLEA1ZAbw+LZOjRgr8H/DjrYw=; b=hRgl7jJTs5Hs7ej4DdE9qaeP7kykOQLq6v5hIAhhFb7L2BPJoiMTl34OTEjaTI3XKZ yajULTCmPIKTRjxL9GOZhT5HSYkMac5NzPm7mA2mGWRNwTmixSVlr0zAb/nrv8G+sV2/ I5CkbPAzjluhMj0vc3qk9ybcECktMbBzfrXwwCSs18U+9nFbHOmV9DoDyQ6jtnIloTBV KW15CfH4myGfndn7NAVfeqYux6vy3UFDnILh2TUYLMVeMuwGP8lvaGWJf5O57zYIo+QE CNLb25+cChIC6+eDLDGIo+Ozu6xBdL5pigw/sL+d/52FFuE+VwX0KFYJDfBRQvU48jfw DiwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705006344; x=1705611144; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w2DckAmZMDW/xUfMFPRLEA1ZAbw+LZOjRgr8H/DjrYw=; b=VVkVDkxHQeiTJM9AtkypiG/yxj4nkaFYkhYpp6yzpLsGpZPQrODEYu1mjvyTuWw/Ff 1TIgSXMbmHXk1Qke4fFCOp1DP51GIb0nILpf9n2k3IjjtF+N3r6ETC4AW+tq7+T17FPI 2mWV1EITB8xTOj2dtnru1ffGGxjzBh0Q8jCIYUoiaN5LGT/uEe0mI4WO5pXDg6lGjIy7 BL/9EP8TykBKAaizrEgvq3attd/8Y3zj5qdbO1Hpdg6283tg604xn8HUWaTu9ZTPaLpL RIjyAiMPckSI9L2THr4hgZV0FLv89vIuE0luwbf9sJxdlhLzdUPD32tkA+LVwyeoSenE pmfg== X-Gm-Message-State: AOJu0YwLQDDvxrxRC8Bvr1Sa1o7fZlVkd2rLmVdnT4hCn3aFFi4Jimmj kHgORYGZpcpTvggbu14pK9+iRTa1bs+N6hoqi79pMbgTyaI= X-Google-Smtp-Source: AGHT+IGHdpq9bKtByPM+d6l+HnIXHqdk71uFcxqNK+HPN1hCNAz2BqQCfF+u1zvNkid6fnlIksEjHWS0z51WXcbteZc= X-Received: by 2002:a2e:998f:0:b0:2cd:3319:ae67 with SMTP id w15-20020a2e998f000000b002cd3319ae67mr172134lji.19.1705006343781; Thu, 11 Jan 2024 12:52:23 -0800 (PST) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 11 Jan 2024 12:52:23 -0800 From: Stefan Kangas In-Reply-To: <87o7dydlcp.fsf@pub.pink> (john muhl's message of "Sat, 06 Jan 2024 18:39:30 -0600") References: <8734vaglxp.fsf@pub.pink> <87o7dydlcp.fsf@pub.pink> MIME-Version: 1.0 Date: Thu, 11 Jan 2024 12:52:23 -0800 Message-ID: Subject: Re: bug#68297: [PATCH] Support indented continuation lines in lua-ts-mode To: john muhl Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 68297-done Cc: 68297-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) john muhl writes: > ...and now I see that only handled top-level statements. This > one works with nested ifs and variables too. Thanks, installed on master (43b4993d73b). From unknown Sat Sep 20 14:55:08 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 09 Feb 2024 12:24:20 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator