[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 1ede907 242/468: Fix several cases for `indent-ne
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 1ede907 242/468: Fix several cases for `indent-new-comment-line' (M-j) |
Date: |
Thu, 5 Aug 2021 04:58:45 -0400 (EDT) |
branch: elpa/lua-mode
commit 1ede9073fd8437bad52aab10e75e9e42c0e58100
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Fix several cases for `indent-new-comment-line' (M-j)
---
Makefile | 1 +
ert-tests/lua-font-lock-test-helpers.el | 23 ++++++++-
ert-tests/test-strings-and-comments.el | 87 +++++++++++++++++++++++++++++++++
lua-mode.el | 5 +-
4 files changed, 113 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 3496186..1a7407c 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ TESTS += ert-tests/test-defun-font-lock.el
TESTS += ert-tests/test-builtin-font-lock.el
TESTS += ert-tests/test-electric-mode.el
TESTS += ert-tests/test-indentation.el
+TESTS += ert-tests/test-strings-and-comments.el
default:
@echo version is $(VERSION)
diff --git a/ert-tests/lua-font-lock-test-helpers.el
b/ert-tests/lua-font-lock-test-helpers.el
index e52fc0f..ce98b32 100644
--- a/ert-tests/lua-font-lock-test-helpers.el
+++ b/ert-tests/lua-font-lock-test-helpers.el
@@ -53,6 +53,9 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
(setq font-lock-verbose nil)
+(defun lua-join-lines (strs)
+ (mapconcat (lambda (x) (concat x "\n")) strs ""))
+
(defmacro with-lua-buffer (&rest body)
`(with-temp-buffer
(switch-to-buffer (current-buffer))
@@ -64,13 +67,29 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
(butlast
(split-string
(with-lua-buffer
- (insert (replace-regexp-in-string
- "^\\s *" "" (mapconcat (lambda (x) (concat x "\n")) strs "")))
+ (insert (replace-regexp-in-string "^\\s *" "" (lua-join-lines strs)))
(indent-region (point-min) (point-max))
(buffer-substring-no-properties
(point-min) (point-max)))
"\n" nil)))
+(defun lua-insert-goto-<> (strs)
+ "Insert sequence of strings and put point in place of \"<>\"."
+ (insert (lua-join-lines strs))
+ (goto-char (point-min))
+ (re-search-forward "<>")
+ (replace-match "")
+ ;; Inserted text may contain multiline constructs which will only be
+ ;; recognized after fontification.
+ (font-lock-fontify-buffer))
+
+(defmacro lua-buffer-strs (&rest body)
+ `(butlast
+ (split-string
+ (with-lua-buffer
+ (progn ,@body)
+ (buffer-substring-no-properties (point-min) (point-max)))
+ "\n" nil)))
(defmacro should-lua-indent (strs)
`(should
(equal ,strs (lua-get-indented-strs ,strs))))
diff --git a/ert-tests/test-strings-and-comments.el
b/ert-tests/test-strings-and-comments.el
new file mode 100644
index 0000000..904805a
--- /dev/null
+++ b/ert-tests/test-strings-and-comments.el
@@ -0,0 +1,87 @@
+(require 'ert)
+(require 'lua-font-lock-test-helpers
+ ;; let's try a bit to help Emacs find the helpers, just in case
+ (concat (file-name-directory (or load-file-name (buffer-file-name)
+ default-directory))
+ "lua-font-lock-test-helpers.el"))
+
+(defmacro should= (lhs rhs)
+ `(should (equal ,lhs ,rhs)))
+
+(ert-deftest lua-M-j-works-for-simple-comment ()
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("-- foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("-- foobar"
+ "-- "))
+
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("xyzzy -- foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("xyzzy -- foobar"
+ "-- "))
+
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("xyz<> xyzzy -- foobar"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("xyz"
+ "xyzzy -- foobar")))
+
+
+(ert-deftest lua-M-j-works-for-longer-comment ()
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("---- foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("---- foobar"
+ "---- "))
+
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("xyzzy ---- foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("xyzzy ---- foobar"
+ "---- ")))
+
+(ert-deftest lua-M-j-handles-string-and-multiline-comments ()
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("\"-- \" .. foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("\"-- \" .. foobar"
+ ""))
+
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("'-- ' .. foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("'-- ' .. foobar"
+ ""))
+
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("[[-- ]] .. foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("[[-- ]] .. foobar"
+ ""))
+
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("--[[-- ]] .. foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("--[[-- ]] .. foobar"
+ ""))
+
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("---[[-- ]] .. foobar <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("---[[-- ]] .. foobar"
+ "---")))
+
+(ert-deftest lua-M-j-works-if-comment-is-empty ()
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("-- <>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("--"
+ "--"))
+
+ ;; Let's make sure that whitespace is optional.
+ (should= (lua-buffer-strs
+ (lua-insert-goto-<> '("--<>"))
+ (execute-kbd-macro (kbd "M-j")))
+ '("--"
+ "--")))
diff --git a/lua-mode.el b/lua-mode.el
index 5942109..314a28d 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -106,6 +106,7 @@
(require 'cl))
(require 'comint)
+(require 'newcomment)
(eval-and-compile
;; Backward compatibility for Emacsen < 24.1
@@ -193,7 +194,7 @@ for Emacsen that doesn't contain one (pre-23.3)."
:type 'string
:group 'lua)
-(defcustom lua-comment-start-skip "-- "
+(defcustom lua-comment-start-skip "---*[ \t]*"
"Default value of `comment-start-skip'."
:type 'string
:group 'lua)
@@ -654,6 +655,8 @@ Groups 6-9 can be used in any of argument regexps."
(indent-line-function . lua-indent-line)
(comment-start . ,lua-comment-start)
(comment-start-skip . ,lua-comment-start-skip)
+ (comment-use-syntax . t)
+ (comment-use-global-state . t)
(imenu-generic-expression . ,lua-imenu-generic-expression)))
;; setup menu bar entry (XEmacs style)
- [nongnu] elpa/lua-mode b124dd0 194/468: Add field containing commit SHA expanded during archive creation., (continued)
- [nongnu] elpa/lua-mode b124dd0 194/468: Add field containing commit SHA expanded during archive creation., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 64c1e94 197/468: lua--builtins: add "self" as keyword, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d6c8419 202/468: Fix incorrect error highlighting in 'for x = ...' statements, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2d94dee 204/468: Don't unindent comment close-bracket if it doesn't match open-bracket, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c1fcfb6 211/468: Add NEWS file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d0fa50d 217/468: lua-make-delimited-matcher: wrap into eval-and-compile, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b684790 219/468: Revert "Rename lua--function-name-rx, use it in font-lock keywords init", Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8e19d23 231/468: Add basic indentation tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6729533 234/468: Rewrite lua-send-buffer function (should fix issue #60), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode afc1ea0 235/468: Send init-code in lua-start-process, enable compilation-shell-minor-mode, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1ede907 242/468: Fix several cases for `indent-new-comment-line' (M-j),
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 6c55abb 245/468: Add lua-rx/-to-string wrappers to simplify writing Lua-specific regexps, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1452f8e 244/468: should-lua-indent: accept strings rather than lists to simplify writing tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a0f3a6f 250/468: Simplify font-lock & imenu regexps with lua-rx, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e430d01 252/468: Remove deprecated test code from test/, put current code there instead, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1d21a10 259/468: Reorganize test structure, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dc55356 261/468: lua-forward-regexp: make sure direction is `forward', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0a986f7 266/468: Add hideshow support for "repeat... until" blocks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8d27d2c 268/468: fixed up tests && improved lua-kill-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 82daeb5 297/468: Merge pull request #88 from tarsius/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7b2c18c 305/468: Merge pull request #99 from tarsius/master, Philip Kaludercic, 2021/08/05