Elisp: Reformat to Sentence Lines

By Xah Lee. Date: . Last updated: .

This command breaks a long line or text block into multile lines, each line is a sentence, ending in a period.

This is useful for editing a thesis or long prose. Because it lets you clearly see the sentence structure.

(defun xah-reformat-to-sentence-lines ()
  "Break a long line or text block into multiple lines by ending period.
Work on text selection if there is one, else the current text block.

URL `http://ergoemacs.org/emacs/elisp_reformat_to_sentence_lines.html'
Version 2020-12-02 2021-04-14"
  (let ($p1 $p2)
    (if (use-region-p)
        (setq $p1 (region-beginning) $p2 (region-end))
        (if (re-search-backward "\n[ \t]*\n+" nil "move")
            (progn (re-search-forward "\n[ \t]*\n+")
                   (setq $p1 (point)))
          (setq $p1 (point)))
        (re-search-forward "\n[ \t]*\n" nil "move")
        (setq $p2 (point))))
      (narrow-to-region $p1 $p2)
      (let ((fill-column most-positive-fixnum ))
        (fill-region (point-min) (point-max)))
      (goto-char (point-min))
      (while (re-search-forward "\\. +\\([0-9A-Za-z]+\\)" nil "NOERROR")
        (replace-match ".\n\\1" )))))

The following are often useful together:

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys


ELisp Examples

ELisp Write Major Mode

ELisp Examples

Xah Commands

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples