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

From: Roi Martin <[email-masked]>
Date: Mon, 02 Jun 2025 15:06:16 +0200

Eli Zaretskii <[email-masked]> writes:

> It's okay, but please make sure there are two spaces between
> sentences, not one.  There are quite a few cases in the patch where
> this is not so.

Fixed in doc strings.  The rest of cases correspond to test data where
we want to verify that `sentence-end-double-space' is respected.

> Also, the commit log message should mention the bug number.

Fixed.

RMS replied to me with a review, where he mentioned that this feature
would be more convenient if it were a minor mode.  Eli, Stefan, what do
you think?  If it makes sense, we can add it in a future patch.

Also, with regard to the paragraph:

  For more details about semantic linefeeds, see `https://sembr.org/' and
  `https://rhodesmill.org/brandon/2012/one-sentence-per-line/'."

He raised the following concern:

> This sort of information doesn't belong in an Emacs doc string.
> If some of it isimportant for using this feature right, we
> should state the point in this and other doc strings, or in
> the Emacs Manual,  That way we can propagate it and update it.

> If information is "if you'd like to know more", not necessary for peopke
> to read to know how to use the feature, then we can refer to it on a web page.
> But we need to have reason to be confident that page will exist for many
> years, serving the same purpose, in a way we would not be ashamed to link to.
> 
> Otherwise, depending on it is asking for trouble.
> 
> How much material is importaht to link to for this purpose?

As I previously said, I think it should be fine to add a short
explanation in the doc string or in the manual instead of linking with
external sites that are subject to change or be deleted in the future.

I've attached a new version of the patch.  It includes the following
changes compared to the previous version:

- Separate sentences in doc strings using two spaces.
- Add bug number to commit log message.
- Slightly reword doc strings, following a suggestion from RMS.
- Add test to check that it is possible to "revert" semlf-filling by
  refilling the paragraph, following a suggestion from RMS.

        Roi

>From db5067064d89ea16b2313622be3e6bb32e9293f4 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-revert)
(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-revert.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.  (Bug#78561)
---
 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 ++
 .../fill-resources/semlf-revert.erts          |  11 ++
 .../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             | 112 +++++++++++
 17 files changed, 1004 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-revert.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..386a88bda3a8 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.  Text is
+refilled putting a newline character after each sentence, calling
+`forward-sentence' to find the ends of sentences.  If
+`sentence-end-double-space' is non-nil, period followed by one space is
+not the end of a sentence.
+
+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.  The variable `fill-column' controls the width for filling.
+
+Return the `fill-prefix' used 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.
+Refill text putting a newline character after each sentence, calling
+`forward-sentence' to find the ends of sentences.  If
+`sentence-end-double-space' is non-nil, period followed by one space is
+not the end of a sentence.
+
+If JUSTIFY is non-nil (interactively, with prefix argument), justify as
+well.  The variable `fill-column' controls the width for filling.
+
+Return the `fill-prefix' used for filling.
+
+You can use this function as the value of `fill-paragraph-function', so
+`fill-paragraph' and other filling commands will use it.
+
+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-revert.erts b/test/lisp/textmodes/fill-resources/semlf-revert.erts
new file mode 100644
index 000000000000..d3efca50de6d
--- /dev/null
+++ b/test/lisp/textmodes/fill-resources/semlf-revert.erts
@@ -0,0 +1,11 @@
+Name: revert
+
+=-=
+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..8fbd9919bad0 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,117 @@ 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-revert ()
+  "Test that the `fill-paragraph-semlf' function can be reverted."
+  (ert-test-erts-file (ert-resource-file "semlf-revert.erts")
+                      (lambda ()
+                        (fill-paragraph)
+			(fill-paragraph-semlf)
+                        (fill-paragraph))))
+
+(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