Subject: Re: bug#78561: [PATCH] Add semantic linefeed support for paragraph filling

From: Roi Martin <[email-masked]>
Date: Wed, 28 May 2025 17:44:02 +0200

Stefan Monnier <[email-masked]> writes:

> I recommend you first finish the current patch and take on that
> plan afterwards.
> What I'm asking is a fairly small refactoring of the code you sent,
> I think.

Please, find attached a new version of the patch.

It contains the following changes:

- Add a new function named `fill-region-as-paragraph-semlf', which fills
  a region using semantic linefeeds as if it were a single paragraph.
  Its behavior is analogous to `fill-region-as-paragraph'.
- Update the `fill-paragraph-semlf' function to use
  `fill-region-as-paragraph-semlf' internally.
- Remove the mention about using `fill-paragraph-semlf' as
  `fill-paragraph-function' from docs, given that the long term plan is
  to obsolete this.
- Add test for `fill-region-as-paragraph-semlf'.

Thanks a lot for all the explanations.  I hope this new version is
closer to what you had in mind.

        Roi

>From 92538223e4808a46d47de57be4e85b3773f1fc8b Mon Sep 17 00:00:00 2001
From: Roi Martin <[email-masked]>
Date: Fri, 21 Mar 2025 14:22:46 +0100
Subject: [PATCH] Add semantic linefeed support for paragraph filling

* lisp/textmodes/fill.el (fill-region-as-paragraph-semlf): Add function
to fill a region using semantic linefeeds as if it were a single
paragraph.
(fill-paragraph-semlf): Add function to fill paragraph using semantic
linefeeds.
* test/lisp/textmodes/fill-tests.el
(fill-test-fill-region-as-paragraph-semlf)
(fill-test-fill-paragraph-semlf)
(fill-test-fill-paragraph-semlf-fill-paragraph-function)
(fill-test-fill-paragraph-semlf-justify)
(fill-test-fill-paragraph-semlf-sentence-end-double-space)
(fill-test-fill-paragraph-semlf-fill-column)
(fill-test-fill-paragraph-semlf-punctuation-marks)
(fill-test-fill-paragraph-semlf-twice)
(fill-test-fill-paragraph-semlf-fill-prefix)
(fill-test-fill-paragraph-semlf-indented-block)
(fill-test-fill-paragraph-semlf-emacs-lisp-mode)
(fill-test-fill-paragraph-semlf-c-mode)
(fill-test-fill-paragraph-semlf-org-mode)
(fill-test-fill-paragraph-semlf-markdown-mode): Add tests.
* test/lisp/textmodes/fill-resources/semlf-c-mode.erts:
* test/lisp/textmodes/fill-resources/semlf-emacs-lisp-mode.erts:
* test/lisp/textmodes/fill-resources/semlf-fill-column.erts:
* test/lisp/textmodes/fill-resources/semlf-fill-paragraph-function.erts:
* test/lisp/textmodes/fill-resources/semlf-fill-prefix.erts:
* test/lisp/textmodes/fill-resources/semlf-fill-region-as-paragraph.erts:
* test/lisp/textmodes/fill-resources/semlf-indented-block.erts:
* test/lisp/textmodes/fill-resources/semlf-justify.erts:
* test/lisp/textmodes/fill-resources/semlf-markdown-mode.erts:
* test/lisp/textmodes/fill-resources/semlf-org-mode.erts:
* test/lisp/textmodes/fill-resources/semlf-punctuation-marks.erts:
* test/lisp/textmodes/fill-resources/semlf-sentence-end-double-space.erts:
* test/lisp/textmodes/fill-resources/semlf-twice.erts:
* test/lisp/textmodes/fill-resources/semlf.erts: Add test data.
---
 lisp/textmodes/fill.el                        |  92 +++++++++
 .../fill-resources/semlf-c-mode.erts          | 183 ++++++++++++++++++
 .../fill-resources/semlf-emacs-lisp-mode.erts |  87 +++++++++
 .../fill-resources/semlf-fill-column.erts     |  15 ++
 .../semlf-fill-paragraph-function.erts        |  12 ++
 .../fill-resources/semlf-fill-prefix.erts     |  35 ++++
 .../semlf-fill-region-as-paragraph.erts       |  37 ++++
 .../fill-resources/semlf-indented-block.erts  |  31 +++
 .../fill-resources/semlf-justify.erts         |  12 ++
 .../fill-resources/semlf-markdown-mode.erts   | 129 ++++++++++++
 .../fill-resources/semlf-org-mode.erts        | 122 ++++++++++++
 .../semlf-punctuation-marks.erts              |  13 ++
 .../semlf-sentence-end-double-space.erts      |  13 ++
 .../textmodes/fill-resources/semlf-twice.erts |  12 ++
 test/lisp/textmodes/fill-resources/semlf.erts |  88 +++++++++
 test/lisp/textmodes/fill-tests.el             | 104 ++++++++++
 16 files changed, 985 insertions(+)
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-c-mode.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-emacs-lisp-mode.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-fill-column.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-fill-paragraph-function.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-fill-prefix.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-fill-region-as-paragraph.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-indented-block.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-justify.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-markdown-mode.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-org-mode.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-punctuation-marks.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-sentence-end-double-space.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf-twice.erts
 create mode 100644 test/lisp/textmodes/fill-resources/semlf.erts

diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index e38d030734fb..b457b01d6917 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -1583,4 +1583,96 @@ fill-individual-paragraphs-citation
 	"")
     string))
 
+(defun fill-region-as-paragraph-semlf (from to &optional justify
+                                            nosqueeze squeeze-after)
+  "Fill the region using semantic linefeeds as if it were a single paragraph.
+This command removes any paragraph breaks in the region and extra
+newlines at the end, and fills lines within the region. It leaves point
+at the beginning of the line following the region.
+
+If JUSTIFY is non-nil (interactively, with prefix argument), justify as
+well.  If NOSQUEEZE is non-nil, do not to make spaces between words
+canonical before filling.  SQUEEZE-AFTER, if non-nil, should be a buffer
+position; it means canonicalize spaces only starting from that position.
+See `canonically-space-region' for the meaning of canonicalization of
+spaces.
+
+Return the `fill-prefix' used for filling.
+
+If `sentence-end-double-space' is non-nil, then period followed by one
+space does not end a sentence, so don't break a line there.
+The variable `fill-column' controls the width for filling.
+
+For more details about semantic linefeeds, see `fill-paragraph-semlf'."
+  (interactive (progn
+		 (barf-if-buffer-read-only)
+		 (list (region-beginning)
+                       (region-end)
+		       (if current-prefix-arg 'full))))
+  (unless (memq justify '(t nil none full center left right))
+    (setq justify 'full))
+
+  (let ((from (min from to))
+        (to (max from to))
+        pfx)
+    (goto-char from)
+    (with-restriction (line-beginning-position) to
+      (let ((fill-column (point-max)))
+        (setq pfx (or (save-excursion
+                        (fill-region-as-paragraph (point)
+                                                  (point-max)
+                                                  nil
+                                                  nosqueeze
+                                                  squeeze-after))
+                      "")))
+      (while (not (eobp))
+        (let ((fill-prefix pfx))
+	  (fill-region-as-paragraph (point)
+				    (progn (forward-sentence) (point))
+				    justify
+                                    nosqueeze
+                                    squeeze-after))
+        (when (and (> (point) (line-beginning-position))
+		   (< (point) (line-end-position)))
+	  (delete-horizontal-space)
+	  (insert "\n")
+	  (insert pfx))))
+    (unless (eobp) (forward-char 1))
+    pfx))
+
+(defun fill-paragraph-semlf (&optional justify)
+  "Fill paragraph at or after point using semantic linefeeds.
+This command ensures that a newline character follows every sentence.
+If a sentence is not followed by a newline character, one is inserted.
+The task of deciding what is considered a sentence is delegated to the
+`forward-sentence' function.
+
+If JUSTIFY is non-nil (interactively, with prefix argument), justify as
+well.  If `sentence-end-double-space' is non-nil, then period followed
+by one space does not end a sentence, so don't break a line there.
+The variable `fill-column' controls the width for filling.
+
+Return the `fill-prefix' used for filling.
+
+For more details about semantic linefeeds, see `https://sembr.org/' and
+`https://rhodesmill.org/brandon/2012/one-sentence-per-line/'."
+  (interactive (progn
+		 (barf-if-buffer-read-only)
+		 (list (if current-prefix-arg 'full))))
+  (unless (memq justify '(t nil none full center left right))
+    (setq justify 'full))
+
+  (save-excursion
+    (let ((to (progn
+		(fill-forward-paragraph 1)
+		(backward-word)
+		(end-of-line)
+		(point)))
+	  (from (progn
+		  (fill-forward-paragraph -1)
+		  (forward-word)
+		  (beginning-of-line)
+		  (point))))
+      (fill-region-as-paragraph-semlf from to justify))))
+
 ;;; fill.el ends here
diff --git a/test/lisp/textmodes/fill-resources/semlf-c-mode.erts b/test/lisp/textmodes/fill-resources/semlf-c-mode.erts
new file mode 100644
index 000000000000..a28eb68cfc6a
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-c-mode.erts
@@ -0,0 +1,183 @@
+Point-Char: |
+
+Name: c-mode - single-line
+
+=-=
+// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+// eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+// ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+// eiusmod tempor.
+// Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+// veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: c-mode - single-line - fill-prefix - marker
+
+=-=
+// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+// - Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+// - Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+// - eiusmod tempor.
+// - Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+// - veniam, quis nostrud exercitation ullamco laboris nisi ut.
+// - Aliquip ex ea commodo consequat.
+// - Duis aute irure dolor in reprehenderit in voluptate velit esse
+// - cillum dolore eu fugiat nulla pariatur.
+// - Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+// - officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: c-mode - single-line - fill-prefix - whitespace
+
+=-=
+// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+//   Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+//   Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+//   eiusmod tempor.
+//   Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+//   veniam, quis nostrud exercitation ullamco laboris nisi ut.
+//   Aliquip ex ea commodo consequat.
+//   Duis aute irure dolor in reprehenderit in voluptate velit esse
+//   cillum dolore eu fugiat nulla pariatur.
+//   Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+//   officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: c-mode - single-line - indented block
+
+=-=
+// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+// eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+// enim ad minim veniam, quis nostrud exercitation ullamco laboris
+// nisi ut.
+//
+// 	|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+// 	do eiusmod tempor.  Incididunt ut labore et dolore magna
+// 	aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+// 	ullamco laboris nisi ut.
+//
+// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+// eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+// enim ad minim veniam, quis nostrud exercitation ullamco laboris
+// nisi ut.
+=-=
+// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+// eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+// enim ad minim veniam, quis nostrud exercitation ullamco laboris
+// nisi ut.
+//
+// 	Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+// 	do eiusmod tempor.
+// 	Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+// 	veniam, quis nostrud exercitation ullamco laboris nisi ut.
+//
+// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+// eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+// enim ad minim veniam, quis nostrud exercitation ullamco laboris
+// nisi ut.
+=-=-=
+
+Name: c-mode - multi-line
+
+=-=
+/*
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ * eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ * ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+ */
+=-=
+/*
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ * eiusmod tempor.
+ * Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+ * veniam, quis nostrud exercitation ullamco laboris nisi ut.
+ */
+=-=-=
+
+Name: c-mode - multi-line - fill-prefix - marker
+
+=-=
+/*
+ * - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+ * - Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ * - Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ */
+=-=
+/*
+ * - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ * - eiusmod tempor.
+ * - Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+ * - veniam, quis nostrud exercitation ullamco laboris nisi ut.
+ * - Aliquip ex ea commodo consequat.
+ * - Duis aute irure dolor in reprehenderit in voluptate velit esse
+ * - cillum dolore eu fugiat nulla pariatur.
+ * - Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+ * - officia deserunt mollit anim id est laborum.
+ */
+=-=-=
+
+Name: c-mode - multi-line - fill-prefix - whitespace
+
+=-=
+/*
+ * - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+ *   Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ *   Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ */
+=-=
+/*
+ * - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ *   eiusmod tempor.
+ *   Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+ *   veniam, quis nostrud exercitation ullamco laboris nisi ut.
+ *   Aliquip ex ea commodo consequat.
+ *   Duis aute irure dolor in reprehenderit in voluptate velit esse
+ *   cillum dolore eu fugiat nulla pariatur.
+ *   Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+ *   officia deserunt mollit anim id est laborum.
+ */
+=-=-=
+
+Name: c-mode - multi-line - indented block
+
+=-=
+/*
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ * eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+ * enim ad minim veniam, quis nostrud exercitation ullamco laboris
+ * nisi ut.
+ *
+ * 	|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+ * 	do eiusmod tempor.  Incididunt ut labore et dolore magna
+ * 	aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ * 	ullamco laboris nisi ut.
+ *
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ * eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+ * enim ad minim veniam, quis nostrud exercitation ullamco laboris
+ * nisi ut.
+ */
+=-=
+/*
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ * eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+ * enim ad minim veniam, quis nostrud exercitation ullamco laboris
+ * nisi ut.
+ *
+ * 	Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+ * 	do eiusmod tempor.
+ * 	Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+ * 	veniam, quis nostrud exercitation ullamco laboris nisi ut.
+ *
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+ * eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+ * enim ad minim veniam, quis nostrud exercitation ullamco laboris
+ * nisi ut.
+ */
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-emacs-lisp-mode.erts b/test/lisp/textmodes/fill-resources/semlf-emacs-lisp-mode.erts
new file mode 100644
index 000000000000..fe71ee32c1aa
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-emacs-lisp-mode.erts
@@ -0,0 +1,87 @@
+Point-Char: |
+
+Name: emacs-lisp-mode
+
+=-=
+;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;; eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+;; ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;; eiusmod tempor.
+;; Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+;; veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: emacs-lisp-mode - fill-prefix - marker
+
+=-=
+;; - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+;; - Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+;; - Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+;; - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;; - eiusmod tempor.
+;; - Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+;; - veniam, quis nostrud exercitation ullamco laboris nisi ut.
+;; - Aliquip ex ea commodo consequat.
+;; - Duis aute irure dolor in reprehenderit in voluptate velit esse
+;; - cillum dolore eu fugiat nulla pariatur.
+;; - Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+;; - officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: emacs-lisp-mode - fill-prefix - whitespace
+
+=-=
+;; - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+;;   Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+;;   Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+;; - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;;   eiusmod tempor.
+;;   Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+;;   veniam, quis nostrud exercitation ullamco laboris nisi ut.
+;;   Aliquip ex ea commodo consequat.
+;;   Duis aute irure dolor in reprehenderit in voluptate velit esse
+;;   cillum dolore eu fugiat nulla pariatur.
+;;   Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+;;   officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: emacs-lisp-mode - indented block
+
+The `fill-forward-paragraph' function jumps to the beginning/end of
+the comment.
+
+=-=
+;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;; eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+;; enim ad minim veniam, quis nostrud exercitation ullamco laboris
+;; nisi ut.
+
+;; 	|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+;; 	do eiusmod tempor.  Incididunt ut labore et dolore magna
+;; 	aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+;; 	ullamco laboris nisi ut.
+
+;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;; eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+;; enim ad minim veniam, quis nostrud exercitation ullamco laboris
+;; nisi ut.
+=-=
+;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;; eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+;; enim ad minim veniam, quis nostrud exercitation ullamco laboris
+;; nisi ut.
+
+;; 	Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+;; 	do eiusmod tempor.
+;; 	Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+;; 	veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+;; eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+;; enim ad minim veniam, quis nostrud exercitation ullamco laboris
+;; nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-fill-column.erts b/test/lisp/textmodes/fill-resources/semlf-fill-column.erts
new file mode 100644
index 000000000000..20db7b1f9c5b
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-fill-column.erts
@@ -0,0 +1,15 @@
+Name: fill-column
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet,
+consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore
+magna aliqua. Ut enim ad minim
+veniam, quis nostrud exercitation
+ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-fill-paragraph-function.erts b/test/lisp/textmodes/fill-resources/semlf-fill-paragraph-function.erts
new file mode 100644
index 000000000000..467e7401cf50
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-fill-paragraph-function.erts
@@ -0,0 +1,12 @@
+Name: fill-paragraph-function
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-fill-prefix.erts b/test/lisp/textmodes/fill-resources/semlf-fill-prefix.erts
new file mode 100644
index 000000000000..e067eff69701
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-fill-prefix.erts
@@ -0,0 +1,35 @@
+Name: fill-prefix - marker
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+- eiusmod tempor.
+- Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+- veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.
+- Duis aute irure dolor in reprehenderit in voluptate velit esse
+- cillum dolore eu fugiat nulla pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+- officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: fill-prefix - whitespace
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+  Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+  Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+  Aliquip ex ea commodo consequat.
+  Duis aute irure dolor in reprehenderit in voluptate velit esse
+  cillum dolore eu fugiat nulla pariatur.
+  Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+  officia deserunt mollit anim id est laborum.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-fill-region-as-paragraph.erts b/test/lisp/textmodes/fill-resources/semlf-fill-region-as-paragraph.erts
new file mode 100644
index 000000000000..114eaa46fc3c
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-fill-region-as-paragraph.erts
@@ -0,0 +1,37 @@
+Point-Char: |
+
+Name: fill-region-as-paragraph-semlf
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, s|ed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+do eiusmod tempor.
+Incididunt ut labore et dolore
+magna aliqua. Ut enim ad minim
+veniam, quis nostrud exercitation
+ullamco laboris nisi ut.
+Lorem ipsum dolor sit amet,
+consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore
+magna aliqua. Ut enim ad minim
+veniam, quis nostrud exercitation
+ullamco laboris nisi ut.
+Lorem ipsum dolor sit amet,
+consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore
+magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-indented-block.erts b/test/lisp/textmodes/fill-resources/semlf-indented-block.erts
new file mode 100644
index 000000000000..e483567c6ab3
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-indented-block.erts
@@ -0,0 +1,31 @@
+Point-Char: |
+
+Name: indented block
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+	|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+	do eiusmod tempor.  Incididunt ut labore et dolore magna
+	aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+	ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+	Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+	do eiusmod tempor.
+	Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+	veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-justify.erts b/test/lisp/textmodes/fill-resources/semlf-justify.erts
new file mode 100644
index 000000000000..3a951b7ce424
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-justify.erts
@@ -0,0 +1,12 @@
+Name: justify
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem  ipsum  dolor sit  amet,  consectetur  adipiscing elit,  sed  do
+eiusmod tempor.
+Incididunt ut labore et dolore magna  aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-markdown-mode.erts b/test/lisp/textmodes/fill-resources/semlf-markdown-mode.erts
new file mode 100644
index 000000000000..7257708c245d
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-markdown-mode.erts
@@ -0,0 +1,129 @@
+Point-Char: |
+
+Name: markdown-mode
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: markdown-mode - list - one single-line item
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: markdown-mode - list - multiple single-line items
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: markdown-mode - list - one multi-line item
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+  enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
+  ut.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: markdown-mode - list - multiple multi-line items
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.  Incididunt ut labore et dolore magn a aliqua. Ut
+  enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
+  ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in
+  reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+  pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+  officia deserunt mollit anim id est laborum.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magn a aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in
+  reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+  pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+  officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: markdown-mode - list - short sentence in multi-line item
+
+=-=
+- Lorem ipsum dolor.  Sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.  Incididunt ut labore et dolore magn a aliqua. Ut
+  enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
+  ut.
+=-=
+- Lorem ipsum dolor.
+  Sit amet, consectetur adipiscing elit, sed do eiusmod tempor.
+  Incididunt ut labore et dolore magn a aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: markdown-mode - indented block
+Skip: t
+
+TODO - In `markdown-mode', the `fill-forward-paragraph' function
+ignores code blocks.  We should reach out to the `markdown-mode'
+maintainer(s) to understand the reason for this and possibly suggest a
+change to this behavior.  This works as expected in
+`markdown-ts-mode'.
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+	|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+	do eiusmod tempor.  Incididunt ut labore et dolore magna
+	aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+	ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+	Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+	do eiusmod tempor.
+	Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+	veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-org-mode.erts b/test/lisp/textmodes/fill-resources/semlf-org-mode.erts
new file mode 100644
index 000000000000..81dd4841de94
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-org-mode.erts
@@ -0,0 +1,122 @@
+Point-Char: |
+
+Name: org-mode
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: org-mode - list - one single-line item
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: org-mode - list - multiple single-line items
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: org-mode - list - one multi-line item
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut
+  enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
+  ut.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: org-mode - list - multiple multi-line items
+
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.  Incididunt ut labore et dolore magn a aliqua. Ut
+  enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
+  ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in
+  reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+  pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+  officia deserunt mollit anim id est laborum.
+=-=
+- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.
+  Incididunt ut labore et dolore magn a aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+- Aliquip ex ea commodo consequat.  Duis aute irure dolor in
+  reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+  pariatur.
+- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+  officia deserunt mollit anim id est laborum.
+=-=-=
+
+Name: org-mode - list - short sentence in multi-line item
+
+=-=
+- Lorem ipsum dolor.  Sit amet, consectetur adipiscing elit, sed do
+  eiusmod tempor.  Incididunt ut labore et dolore magn a aliqua. Ut
+  enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
+  ut.
+=-=
+- Lorem ipsum dolor.
+  Sit amet, consectetur adipiscing elit, sed do eiusmod tempor.
+  Incididunt ut labore et dolore magn a aliqua. Ut enim ad minim
+  veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: org-mode - indented block
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+	|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+	do eiusmod tempor.  Incididunt ut labore et dolore magna
+	aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+	ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+	Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
+	do eiusmod tempor.
+	Incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+	veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-punctuation-marks.erts b/test/lisp/textmodes/fill-resources/semlf-punctuation-marks.erts
new file mode 100644
index 000000000000..5346216e9f9c
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-punctuation-marks.erts
@@ -0,0 +1,13 @@
+Name: punctuation marks
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua!  Ut enim
+ad minim veniam?  Quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua!
+Ut enim ad minim veniam?
+Quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-sentence-end-double-space.erts b/test/lisp/textmodes/fill-resources/semlf-sentence-end-double-space.erts
new file mode 100644
index 000000000000..a01beed0f665
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-sentence-end-double-space.erts
@@ -0,0 +1,13 @@
+Name: sentence-end-double-space
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua.
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf-twice.erts b/test/lisp/textmodes/fill-resources/semlf-twice.erts
new file mode 100644
index 000000000000..862dda6e27eb
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-twice.erts
@@ -0,0 +1,12 @@
+Name: fill twice
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-resources/semlf.erts b/test/lisp/textmodes/fill-resources/semlf.erts
new file mode 100644
index 000000000000..f3e331cd9381
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf.erts
@@ -0,0 +1,88 @@
+Point-Char: |
+
+Name: beginning of buffer
+
+=-=
+|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: second paragraph
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
+
+Name: end of buffer
+
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.|
+=-=
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.  Incididunt ut labore et dolore magna aliqua. Ut enim
+ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+eiusmod tempor.
+Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+quis nostrud exercitation ullamco laboris nisi ut.
+=-=-=
diff --git a/test/lisp/textmodes/fill-tests.el b/test/lisp/textmodes/fill-tests.el
index 6e079973100e..1448965c9d46 100644
--- a/test/lisp/textmodes/fill-tests.el
+++ b/test/lisp/textmodes/fill-tests.el
@@ -28,6 +28,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 
 (ert-deftest fill-test-no-fill-polish-nobreak-p nil
   "Tests of the `fill-polish-nobreak-p' function."
@@ -121,6 +122,109 @@ test-fill-haskell
   ;; w
 ")))
 
+
+(ert-deftest fill-test-fill-region-as-paragraph-semlf ()
+  "Test the `fill-region-as-paragraph-semlf' function."
+  (ert-test-erts-file (ert-resource-file "semlf-fill-region-as-paragraph.erts")
+                      (lambda ()
+			(setq-local fill-column 35)
+			(fill-region-as-paragraph-semlf
+                         (point)
+                         (progn
+                           (goto-char (point-max))
+                           (forward-line -1)
+                           (beginning-of-line)
+                           (point))))))
+
+(ert-deftest fill-test-fill-paragraph-semlf ()
+  "Test the `fill-paragraph-semlf' function."
+  (ert-test-erts-file (ert-resource-file "semlf.erts")
+                      (lambda ()
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-fill-paragraph-function ()
+  "Test `fill-paragraph-semlf' as `fill-paragraph-function'."
+  (ert-test-erts-file (ert-resource-file "semlf-fill-paragraph-function.erts")
+                      (lambda ()
+			(setq-local fill-paragraph-function #'fill-paragraph-semlf)
+			(fill-paragraph))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-justify ()
+  "Test the JUSTIFY parameter of the `fill-paragraph-semlf' function."
+  (ert-test-erts-file (ert-resource-file "semlf-justify.erts")
+                      (lambda ()
+			(fill-paragraph-semlf 'justify))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-sentence-end-double-space ()
+  "Test the `fill-paragraph-semlf' function with `sentence-end-double-space'."
+  (ert-test-erts-file (ert-resource-file "semlf-sentence-end-double-space.erts")
+                      (lambda ()
+			(setq-local sentence-end-double-space nil)
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-fill-column ()
+  "Test the `fill-paragraph-semlf' function with `fill-column'."
+  (ert-test-erts-file (ert-resource-file "semlf-fill-column.erts")
+                      (lambda ()
+			(setq-local fill-column 35)
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-punctuation-marks ()
+  "Test the `fill-paragraph-semlf' function with different punctuation marks."
+  (ert-test-erts-file (ert-resource-file "semlf-punctuation-marks.erts")
+                      (lambda ()
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-twice ()
+  "Test to run the `fill-paragraph-semlf' function twice."
+  (ert-test-erts-file (ert-resource-file "semlf-twice.erts")
+                      (lambda ()
+			(goto-char (point-min))
+			(fill-paragraph-semlf)
+			(goto-char (point-min))
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-fill-prefix ()
+  "Test the `fill-paragraph-semlf' function with different fill prefixes."
+  (ert-test-erts-file (ert-resource-file "semlf-fill-prefix.erts")
+                      (lambda ()
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-indented-block ()
+  "Test the `fill-paragraph-semlf' function with an indented block."
+  (ert-test-erts-file (ert-resource-file "semlf-indented-block.erts")
+                      (lambda ()
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-emacs-lisp-mode ()
+  "Test the `fill-paragraph-semlf' function with `emacs-lisp-mode'."
+  (ert-test-erts-file (ert-resource-file "semlf-emacs-lisp-mode.erts")
+                      (lambda ()
+			(emacs-lisp-mode)
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-c-mode ()
+  "Test the `fill-paragraph-semlf' function with `c-mode'."
+  (ert-test-erts-file (ert-resource-file "semlf-c-mode.erts")
+                      (lambda ()
+			(c-mode)
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-org-mode ()
+  "Test the `fill-paragraph-semlf' function with `org-mode'."
+  (ert-test-erts-file (ert-resource-file "semlf-org-mode.erts")
+                      (lambda ()
+			(org-mode)
+			(fill-paragraph-semlf))))
+
+(ert-deftest fill-test-fill-paragraph-semlf-markdown-mode ()
+  "Test the `fill-paragraph-semlf' function with `markdown-mode'."
+  (skip-unless (functionp 'markdown-mode))
+  (ert-test-erts-file (ert-resource-file "semlf-markdown-mode.erts")
+                      (lambda ()
+			(markdown-mode)
+			(fill-paragraph-semlf))))
+
 (provide 'fill-tests)
 
 ;;; fill-tests.el ends here
-- 
2.49.0