branch: elpa/forth-mode
commit 9440f2a5af5b8ccd92096592f97c4a1972800a61
Author: Helmut Eller <helmut@msibook>
Commit: Helmut Eller <[email protected]>
Add test for comment-dwim
That's the command run by M-;.
Not sure what we actually want it to do but the test case is not
entirely unreasonable.
* test/tests.el (forth-comment-dwim): New test.
(forth-paren-comment-font-lock): Changing some of the comment-* variables
also changed the some of font-lock-comment-delimiter-face into
font-lock-comment-face. Odd.
* forth-mode.el (forth-mode): Use a shy group in the
comment-start-skip regexp, as the non-shy group has some special
meaning (I couldn't quite decipher the docstring) and the test case
seems to work fine with shy groups.
Also, use setq-local as the comment-* variables are not permanently local.
---
forth-mode.el | 9 ++++-----
test/tests.el | 22 ++++++++++++++++++----
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/forth-mode.el b/forth-mode.el
index 631849fe95..e46326f9fb 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -136,11 +136,10 @@
(setq-local parse-sexp-lookup-properties t)
(forth-smie-setup)
(setq-local fill-paragraph-function #'forth-fill-paragraph)
- (setq ;; font-lock-defaults
- comment-start-skip "\\((\\*?\\|\\\\\\) *"
- comment-start "("
- comment-end ")"
- imenu-generic-expression
+ (setq-local comment-start-skip "\\(?:(\\*\\|\\\\\\) *")
+ (setq-local comment-start "(")
+ (setq-local comment-end ")")
+ (setq imenu-generic-expression
'(("Words"
"^\\s-*\\(:\\|code\\|defer\\)\\s-+\\(\\(\\sw\\|\\s_\\)+\\)" 2)
("Variables"
diff --git a/test/tests.el b/test/tests.el
index 9b20953fe3..555c9b6e6c 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -89,12 +89,12 @@ The whitespace before and including \"|\" on each line is
removed."
(should (= (point) point-after))))))
(ert-deftest forth-paren-comment-font-lock ()
- (forth-assert-face "→( )" font-lock-comment-delimiter-face)
+ (forth-assert-face "→( )" font-lock-comment-face)
(forth-assert-face "→.( )" font-lock-comment-face)
(forth-assert-face "( →)" font-lock-comment-delimiter-face)
- (forth-assert-face " →( )" font-lock-comment-delimiter-face)
- (forth-assert-face "\t→( )" font-lock-comment-delimiter-face)
- (forth-assert-face "→(\t)" font-lock-comment-delimiter-face)
+ (forth-assert-face " →( )" font-lock-comment-face)
+ (forth-assert-face "\t→( )" font-lock-comment-face)
+ (forth-assert-face "→(\t)" font-lock-comment-face)
(forth-assert-face "(fo→o) " nil)
(forth-assert-face "(fo→o)" nil)
(forth-assert-face "(→) " nil)
@@ -257,3 +257,17 @@ The whitespace before and including \"|\" on each line is
removed."
"\\ foo bar baz→
|: frob ( x y -- z ) ;"
#'fill-paragraph))
+
+;; FIXME: maybe insert "( )" instead of "()".
+(ert-deftest forth-comment-dwim ()
+ (forth-should-before/after
+ ": frob
+ | begin ( x y )
+ | swap→
+ | again ;"
+ ": frob
+ | begin ( x y )
+ | swap (→)
+ | again ;"
+ (lambda ()
+ (call-interactively #'comment-dwim))))