branch: elpa/forth-mode
commit 1bc27cd6b68cbd76c785eee10f64dc969237cdb0
Author: Helmut Eller <[email protected]>
Commit: Helmut Eller <[email protected]>
Support paragraph filling in comments
* forth-mode.el (forth-fill-paragraph): New.
(forth-mode): Initialize fill-paragraph-function.
* test/tests.el (forth-fill-comment): New test.
(forth-strip-|-and-↓, forth-should-before/after): New helpers.
---
forth-mode.el | 10 ++++++++++
test/tests.el | 26 ++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/forth-mode.el b/forth-mode.el
index deff50e903..b546837caa 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -110,6 +110,15 @@
(or (forth-block-with-newlines-p)
(forth-block-without-newlines-p))))
+;; This just calls the standard `fill-paragraph' with adjusted
+;; paramaters.
+(defun forth-fill-paragraph (&rest args)
+ (let ((fill-paragraph-function nil)
+ (fill-paragraph-handle-comment t)
+ (comment-start "\ ")
+ (comment-end ""))
+ (apply #'fill-paragraph args)))
+
(unless (fboundp 'prog-mode)
(defalias 'prog-mode 'fundamental-mode))
@@ -129,6 +138,7 @@
(setq-local syntax-propertize-function #'forth-syntax-propertize))
(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 "("
diff --git a/test/tests.el b/test/tests.el
index 1bf7e55805..7026be1faa 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -63,6 +63,24 @@ The whitespace before and including \"|\" on each line is
removed."
(forward-word)
(should (= (point) end))))
+(defun forth-strip-|-and-↓ (string)
+ (let* ((s2 (forth-strip-| string))
+ (pos (string-match "↓" s2)))
+ (cons (delete ?↓ s2) pos)))
+
+(defun forth-should-before/after (before after fun)
+ (let* ((before+point (forth-strip-|-and-↓ before))
+ (before (car before+point))
+ (point-before (cdr before+point))
+ (after+point (forth-strip-|-and-↓ after))
+ (after (car after+point))
+ (point-after (cdr after+point)))
+ (forth-with-temp-buffer before
+ (goto-char point-before)
+ (funcall fun)
+ (should (string= after (substring-no-properties (buffer-string))))
+ (should (= (point) point-after)))))
+
(ert-deftest forth-paren-comment-font-lock ()
(forth-assert-face "( )" 1 font-lock-comment-delimiter-face)
(forth-assert-face ".( )" 1 font-lock-comment-face)
@@ -211,3 +229,11 @@ The whitespace before and including \"|\" on each line is
removed."
(equal (forth-spec--build-url "SWAP" 2012)
"http://www.forth200x.org/documents/html/core.html#core:SWAP")))
+(ert-deftest forth-fill-comment ()
+ (forth-should-before/after
+ "\\ foo bar
+ |\\ baz↓
+ |: frob ( x y -- z ) ;"
+ "\\ foo bar baz↓
+ |: frob ( x y -- z ) ;"
+ #'fill-paragraph))