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: Fri, 13 Oct 2023 21:19:48 -0500 Message-ID: <87wmvnx5fi.fsf@pub.pink> References: <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="37533"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66466@debbugs.gnu.org, Stefan Kangas To: Eshel Yaron Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 15 17:39:00 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 1qs3Cl-0009Vx-PW for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Oct 2023 17:38:59 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qs3CV-0003R1-6w; Sun, 15 Oct 2023 11:38:43 -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 1qs3CQ-0003Ql-JL for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 11:38:38 -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 1qs3CQ-0006EM-B6 for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 11:38:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qs3Co-00029J-A9 for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 11:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: john muhl Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Oct 2023 15:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66466 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66466-submit@debbugs.gnu.org id=B66466.16973842928184 (code B ref 66466); Sun, 15 Oct 2023 15:39:02 +0000 Original-Received: (at 66466) by debbugs.gnu.org; 15 Oct 2023 15:38:12 +0000 Original-Received: from localhost ([127.0.0.1]:53968 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qs3Bz-00027w-TW for submit@debbugs.gnu.org; Sun, 15 Oct 2023 11:38:12 -0400 Original-Received: from out-208.mta0.migadu.com ([91.218.175.208]:38180) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qs3Bx-00027h-Di for 66466@debbugs.gnu.org; Sun, 15 Oct 2023 11:38:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1697384261; 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=86jZ4qtu+r2OhivAxBgmz2ll6bNe71nMPoUt4iQ5ljM=; b=HikybaSkehwSwFe4zpY3C1uhQ7i2KZyNqZqWSRql0wY/mXf+kEGmsBJbogpiksE8OA7rr9 4l1Oxim/cuKOy6T5cIRusch8ZtR8hHNoPlDnnJ0BuU32gSP1fxjy82aJPv/O56xJLfcSJG ieJXEp0rSBIMNn318YMCf1a3jBlmAS0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: X-Migadu-Flow: FLOW_OUT 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:272524 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eshel Yaron writes: > Hi, > > Stefan Kangas writes: > >> john muhl via "Bug reports for GNU Emacs, the Swiss army knife of text >> editors" writes: >> >>> Add support for using align in Lua files. >> >> nThanks. >> >>> 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 >>> "=3D" >>> (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-*\\)=3D\\(\\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))))))) >> >> Should `lua-mode' also be in `modes'? > > Another option would be for `lua-ts-mode` to define > `align-mode-rules-list` locally, instead of extending `align-rules-list` > globally. > > Also, I noticed that we already have several similar rules for aligning > assignments and comments in `align-rules-list`. Do none of them work > for Lua? The toml-assignment rule works well enough. I added the Lua modes there now. > If so, I wonder what specifics of Lua's syntax make the existing rules > inapplicable. For comments I only see the open-comment and c++-comment rules. open-comment doesn=E2=80=99t match trailing line comments. Extending c++-co= mment in the obvious way (Lua uses "--" for comment start) causes trouble with c++ code like: int x =3D 5; // declare x--; // decrement Lua shares comment syntax with at least Ada, Haskell, SQL and VHDL so I changed the name of the rule to double-dash-comment and added the Lua modes there. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Support-lua-ts-mode-in-align.el.patch >From ac444d12b7a6098bb609a0b9e48c19094ba2be7d 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 | 13 ++++- 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, 88 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..9fa78525ecb 100644 --- a/lisp/align.el +++ b/lisp/align.el @@ -577,7 +577,18 @@ 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-mode lua-ts-mode))) + + (double-dash-comment + (regexp . ,(rx (group (zero-or-more (syntax whitespace))) + "--" + (zero-or-more nonl))) + (modes . '(lua-mode 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..b0473ad6cdf --- /dev/null +++ b/test/lisp/align-resources/lua-ts-mode.erts @@ -0,0 +1,67 @@ +Name: align assignments + +=-= +local first=1 +local s =2 +local last=3 +=-= +local first = 1 +local s = 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 --=-=-=--