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

From: Roi Martin <[email-masked]>
Date: Fri, 23 May 2025 11:58:02 +0200

Tags: patch

This patch adds semantic linefeed support for paragraph filling.  The
functionality has been discussed in the emacs-devel mailing list in the
following threads:

- Fill paragraph using semantic linefeeds: https://lists.gnu.org/archive/html/emacs-devel/2025-03/msg00035.html
- [GNU ELPA] New package: semlf: https://lists.gnu.org/archive/html/emacs-devel/2025-03/msg00702.html

In the second thread we agreed on sending a patch to core instead of
adding a new package to GNU ELPA.

Given that this is a first version, I have not added any reference to
the manuals.  If you think it makes sense, please let me know and I'll
modify the patch accordingly.

What follows is a detailed explanation of the term semantic linefeeds,
so we have all the information in one single place.

The term "semantic linefeeds" or "semantic line breaks" refers to a set
of conventions for using insensitive vertical whitespace to structure
prose along semantic boundaries.

The concept was first introduced by Brian Kernighan in "UNIX for
Beginners" [1] in October 1974.

  Hints for Preparing Documents
  
  Most documents go through several versions (always more than you
  expected) before they are finally finished.  Accordingly, you should
  do whatever possible to make the job of changing them easy.
  
  First, when you do the purely mechanical operations of typing, type so
  subsequent editing will be easy.  Start each sentence on a new line.
  Make lines short, and break lines at natural places, such as after
  commas and semicolons, rather than randomly.  Since most people change
  documents by rewriting phrases and adding, deleting and rearranging
  sentences, these precautions simplify any editing you have to do
  later.

Semantic linefeeds are usually used with markup languages that are not
sensitive to newlines when exported to a different format (e.g. Org,
Texinfo, Markdown).

Let's say that we have the following paragraph in an Org document:

  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.

After filling the paragraph using semantic linefeeds, the result is:

  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.

However, when exported, in both cases the result is:

  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.

So, what are the benefits?

One of the greatest benefits is that semantic linefeeds are "diff
friendly".

For example,

  -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.
  +Lorem ipsum dolor sit amet, XXXXX 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.

Versus,

  -Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
  -tempor.
  +Lorem ipsum dolor sit amet, XXXXX 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.

Semantic linefeeds make easier to spot that the word "XXXXX" was added
in the first line.

Also, they are convenient during code reviews.  Shorter diffs and
separating "ideas" with newlines allow to be more accurate when adding
comments.

The site "Semantic Line Breaks" [2] by Mattt and the blog post "Semantic
Linefeeds" [3] by Brandon Rhodes are both excellent references.

[1] https://web.archive.org/web/20130108163017if_/http://miffy.tom-yam.or.jp:80/2238/ref/beg.pdf
[2] https://sembr.org/
[3] https://rhodesmill.org/brandon/2012/one-sentence-per-line/

>From 8faa17e5ddc8156a6f9f18965bb34e477d5d8b1d 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-paragraph-semlf): Add function to fill
paragraph using semantic linefeeds.
* test/lisp/textmodes/fill-tests.el (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-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                        |  40 ++++
 .../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 ++++
 .../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             |  90 +++++++++
 15 files changed, 882 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-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..676c1657b666 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -1583,4 +1583,44 @@ fill-individual-paragraphs-citation
 	"")
     string))
 
+(defun fill-paragraph-semlf (&optional justify)
+  "Fill paragraph at or after point using semantic linefeeds.
+
+This function ensures that a newline character follows every
+sentence, as punctuated by a period (.), exclamation mark (!), or
+question mark (?).
+
+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."
+  (interactive "P")
+  (save-excursion
+    (let ((end (progn
+		 (fill-forward-paragraph 1)
+		 (backward-word)
+		 (end-of-line)
+		 (point)))
+	  (start (progn
+		   (fill-forward-paragraph -1)
+		   (forward-word)
+		   (beginning-of-line)
+		   (point)))
+	  pfx)
+      (with-restriction start end
+	(let ((fill-column (point-max)))
+	  (setq pfx (or (fill-region-as-paragraph (point-min) (point-max)) "")))
+	(goto-char (point-min))
+	(while (not (eobp))
+	  (let ((fill-prefix pfx))
+	    (fill-region-as-paragraph (point)
+				      (progn (forward-sentence) (point))
+				      justify))
+	  (when (and (> (point) (line-beginning-position))
+		     (< (point) (line-end-position)))
+	    (delete-horizontal-space)
+	    (newline)
+	    (insert pfx))))))
+  t)
+
 ;;; 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-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..afd17c52dcd5 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,95 @@ test-fill-haskell
   ;; w
 ")))
 
+(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