From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: john muhl via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66466: [PATCH] Support lua-ts-mode in align.el Date: Wed, 11 Oct 2023 11:57:05 -0500 Message-ID: <87bkd5oyoj.fsf@pub.pink> Reply-To: john muhl Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27463"; mail-complaints-to="usenet@ciao.gmane.io" To: 66466@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 11 19:30:12 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qqd2B-0006sF-SA for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 11 Oct 2023 19:30:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqd1s-00074l-Fk; Wed, 11 Oct 2023 13:29:52 -0400 Original-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 1qqd1q-00074F-OI for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:50 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqd1h-0000PL-LF for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qqd23-0001Ia-HQ for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:30:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: john muhl Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Oct 2023 17:30:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66466 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16970453984825 (code B ref -1); Wed, 11 Oct 2023 17:30:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Oct 2023 17:29:58 +0000 Original-Received: from localhost ([127.0.0.1]:39992 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqd1x-0001Fk-Dv for submit@debbugs.gnu.org; Wed, 11 Oct 2023 13:29:57 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:36974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqd1u-0001FU-Qp for submit@debbugs.gnu.org; Wed, 11 Oct 2023 13:29:55 -0400 Original-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 1qqd1S-000715-Ma for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:26 -0400 Original-Received: from out-198.mta0.migadu.com ([2001:41d0:1004:224b::c6]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqd1Q-0000NR-ME for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:26 -0400 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=1697045359; 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=UbJWDuvRxEcL6u2oCqhXM2nHteE3FZmT1hWAFTzf3yI=; b=qdfrEG0FSyt+6lFOAEynUf3zoFhm0IAy8gcyeV0RgEC6s7kcSv1uBv/LFggG6uOl1reEEN y0jO9hkI/eS29G3UXD9R1EEZsB9vIdvhVw0b/MSXu5auaB5eJwn85BESTTQtU5WtvpDOnw e+NslELziSOuVDe5R4NevsipJ4evPLY= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:1004:224b::c6; envelope-from=jm@pub.pink; helo=out-198.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272259 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Add support for using align in Lua files. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Support-lua-ts-mode-in-align.el.patch >From 4ba4f08b1c9e11b19c52a946917145ab08b989d6 Mon Sep 17 00:00:00 2001 From: john muhl Date: Tue, 10 Oct 2023 09:18:10 -0500 Subject: [PATCH] Support lua-ts-mode in align.el * lisp/align.el (align-rules-list): Add lua-ts-mode. * lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Indent region before aligning. * test/lisp/align-tests.el (align-lua): * test/lisp/align-resources/lua-ts-mode.erts: Add tests. --- lisp/align.el | 18 +++++- lisp/progmodes/lua-ts-mode.el | 3 + test/lisp/align-resources/lua-ts-mode.erts | 67 ++++++++++++++++++++++ test/lisp/align-tests.el | 6 ++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 test/lisp/align-resources/lua-ts-mode.erts diff --git a/lisp/align.el b/lisp/align.el index a286addb51f..e6e62ce5726 100644 --- a/lisp/align.el +++ b/lisp/align.el @@ -577,7 +577,23 @@ align-rules-list "=" (group (zero-or-more (syntax whitespace))))) (group . (1 2)) - (modes . '(conf-toml-mode toml-ts-mode)))) + (modes . '(conf-toml-mode toml-ts-mode))) + + (lua-assignment + (regexp . ,(concat "\\(?:^\\(?:\\s-*\\(?:local\\s-+\\)?\\(?:[,<>_]" + "\\|\\w\\)+\\)+\\(\\s-*\\)=\\(\\s-*\\)\\)")) + (group . (1 2)) + (modes . '(lua-ts-mode)) + (tab-stop . nil)) + + (lua-comment + (regexp . "\\(?:\\(\\s-*\\)--.*\\)") + (modes . '(lua-ts-mode)) + (column . comment-column) + (valid . ,(lambda () + (save-excursion + (goto-char (match-beginning 1)) + (not (bolp))))))) "A list describing all of the available alignment rules. The format is: diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 224199dff74..8db6816d6e4 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -472,6 +472,9 @@ lua-ts-mode "function")) symbol-end))))) + ;; Align. + (setq-local align-indent-before-aligning t) + (treesit-major-mode-setup)) (add-hook 'flymake-diagnostic-functions #'lua-ts-flymake-luacheck nil 'local)) diff --git a/test/lisp/align-resources/lua-ts-mode.erts b/test/lisp/align-resources/lua-ts-mode.erts new file mode 100644 index 00000000000..ad67c331787 --- /dev/null +++ b/test/lisp/align-resources/lua-ts-mode.erts @@ -0,0 +1,67 @@ +Name: align assignments + +=-= +local first=1 +local second=2 +local last=3 +=-= +local first = 1 +local second = 2 +local last = 3 +=-=-= + +Name: align fields + +=-= +local Table={ +first=1, +second=2, +last=3, +} +=-= +local Table = { + first = 1, + second = 2, + last = 3, +} +=-=-= + +Name: align comments + +=-= +local first-- 1 +local second -- 2 +local last -- 3 +=-= +local first -- 1 +local second -- 2 +local last -- 3 +=-=-= + +Name: align assignments and comments + +=-= +local first=1--one +local second=2 --two +local last=3 --three +=-= +local first = 1 --one +local second = 2 --two +local last = 3 --three +=-=-= + +Name: align fields and comments + +=-= +local T={ +first=1,--one +second=2, --two +last=3, --three +} +=-= +local T = { + first = 1, --one + second = 2, --two + last = 3, --three +} +=-=-= diff --git a/test/lisp/align-tests.el b/test/lisp/align-tests.el index a4d9303827f..4216ad95f4b 100644 --- a/test/lisp/align-tests.el +++ b/test/lisp/align-tests.el @@ -49,6 +49,12 @@ align-latex (ert-test-erts-file (ert-resource-file "latex-mode.erts") (test-align-transform-fun #'latex-mode))) +(ert-deftest align-lua () + (let ((comment-column 20) + (indent-tabs-mode nil)) + (ert-test-erts-file (ert-resource-file "lua-ts-mode.erts") + (test-align-transform-fun #'lua-ts-mode)))) + (ert-deftest align-python () (ert-test-erts-file (ert-resource-file "python-mode.erts") (test-align-transform-fun #'python-mode))) -- 2.41.0 --=-=-=--