From: john muhl via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 66466@debbugs.gnu.org
Subject: bug#66466: [PATCH] Support lua-ts-mode in align.el
Date: Wed, 11 Oct 2023 11:57:05 -0500 [thread overview]
Message-ID: <87bkd5oyoj.fsf@pub.pink> (raw)
[-- Attachment #1: Type: text/plain, Size: 56 bytes --]
Tags: patch
Add support for using align in Lua files.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-lua-ts-mode-in-align.el.patch --]
[-- Type: text/patch, Size: 4132 bytes --]
From 4ba4f08b1c9e11b19c52a946917145ab08b989d6 Mon Sep 17 00:00:00 2001
From: john muhl <jm@pub.pink>
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
next reply other threads:[~2023-10-11 16:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 16:57 john muhl via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-10-12 7:35 ` bug#66466: [PATCH] Support lua-ts-mode in align.el Stefan Kangas
2023-10-12 8:36 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-12 11:20 ` Stefan Kangas
2023-10-14 2:19 ` john muhl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-21 10:27 ` Stefan Kangas
2023-10-13 3:13 ` john muhl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-15 14:25 ` Stefan Kangas
2023-10-15 14:59 ` Philip Kaludercic
2023-10-15 15:18 ` Stefan Kangas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bkd5oyoj.fsf@pub.pink \
--to=bug-gnu-emacs@gnu.org \
--cc=66466@debbugs.gnu.org \
--cc=jm@pub.pink \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).