all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#66466: [PATCH] Support lua-ts-mode in align.el
@ 2023-10-11 16:57 john muhl via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-10-12  7:35 ` Stefan Kangas
  0 siblings, 1 reply; 10+ messages in thread
From: john muhl via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-10-11 16:57 UTC (permalink / raw)
  To: 66466

[-- 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-10-21 10:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 16:57 bug#66466: [PATCH] Support lua-ts-mode in align.el john muhl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-12  7:35 ` 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.