[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a838bcb23c6 1/2: Support lua-ts-mode in align.el
From: |
Stefan Kangas |
Subject: |
master a838bcb23c6 1/2: Support lua-ts-mode in align.el |
Date: |
Sat, 21 Oct 2023 06:27:02 -0400 (EDT) |
branch: master
commit a838bcb23c60fe5bd29a1013a8c75796420ee461
Author: john muhl <jm@pub.pink>
Commit: Stefan Kangas <stefankangas@gmail.com>
Support lua-ts-mode in align.el
* lisp/align.el (align-rules-list): Add lua-ts-mode. (Bug#66466)
* 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 | 7 ++++
4 files changed, 89 insertions(+), 1 deletion(-)
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 @@ The possible settings for `align-region-separate' are:
"="
(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 030a3585158..69833297073 100644
--- a/lisp/progmodes/lua-ts-mode.el
+++ b/lisp/progmodes/lua-ts-mode.el
@@ -443,6 +443,9 @@ Calls REPORT-FN directly."
"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 <const> =2
+local last=3
+=-=
+local first = 1
+local s <const> = 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..e5fcd255907 100644
--- a/test/lisp/align-tests.el
+++ b/test/lisp/align-tests.el
@@ -49,6 +49,13 @@
(ert-test-erts-file (ert-resource-file "latex-mode.erts")
(test-align-transform-fun #'latex-mode)))
+(ert-deftest align-lua ()
+ (skip-unless (treesit-ready-p '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)))