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

From: Roi Martin <[email-masked]>
Date: Sun, 25 May 2025 20:46:58 +0200

Stefan Monnier <[email-masked]> writes:

>> 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.
>
> Maybe a short version of the explanation you give below would be good to
> have in the manual (tho Eli suggests a URL instead, so maybe that's
> good enough?).
>
>> +(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 (?).
>
> This seems inaccurate: it just uses whichever definition of sentence is
> used by `forward-sentence`, so it may ignore some of those chars or pay
> attention to others.

I have updated the patch with a more precise definition.  Also, I added
links to the sources I referenced for semantic linefeeds.

>> +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."
>
> I'd move the "The" to the last line.  🙂

Fixed :)

>> +  (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)
>
> Please try and separate it into a `fill-region-semlf` function and then
> another one which applies it to a paragraph, so that it can also be used
> to fill a specific user-specified region (or the whole buffer).

I'm not sure about this one.  The idea is that `fill-paragraph-semlf'
can be assigned as a value for `fill-paragraph-function' (I also
included a mention to this in the doc string) or it ca be called
directly.  The thing is that `fill-paragraph' docs say:

  The REGION argument is non-nil if called interactively; in that
  case, if Transient Mark mode is enabled and the mark is active,
  call `fill-region' to fill each of the paragraphs in the active
  region, instead of just filling the current paragraph.

And `fill-paragraph-function' docs say:

  Note: This only affects ‘fill-paragraph’ and not ‘fill-region’
  nor ‘auto-fill-mode’

So, if I'm not wrong, filling regions and paragraphs is different in the
current design.

I agree that it would be useful to apply `fill-paragraph-semlf' on a
region or the whole buffer.  But, the same could be said about any other
`fill-paragraph-function'.  So, do we really want a specific
`fill-region-semlf' function?

I attach a new version of the patch.

Thanks!

>From 9b8a28910a3da271afe32377926fd6cc2a9356ff 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                        |  47 +++++
 .../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, 889 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..b6b413f88b2d 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -1583,4 +1583,51 @@ 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.
+If a sentence is not followed by a newline character, one is inserted.
+The task of deciding what is considered a sentence is delegated to the
+`forward-sentence' function.
+
+If JUSTIFY is non-nil (interactively, with prefix argument), justify as
+well.  If `sentence-end-double-space' is non-nil, then period followed
+by one space does not end a sentence, so don't break a line there.
+The variable `fill-column' controls the width for filling.
+
+This function can be assigned as a value for `fill-paragraph-function',
+allowing `fill-paragraph' to utilize it.
+
+For more details about semantic linefeeds, see `https://sembr.org/' and
+`https://rhodesmill.org/brandon/2012/one-sentence-per-line/'."
+  (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)
+	    (insert "\n")
+	    (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