Elisp: Reformat to Sentence Lines

By Xah Lee. Date: .

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.
Version 2020-12-02"
  (interactive)
  (let ($p1 $p2)
    (if (use-region-p)
        (setq $p1 (region-beginning) $p2 (region-end))
      (progn
        (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))))
    (save-restriction
      (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 "\\. +\\([A-Z][a-z]+\\)" nil "NOERROR")
        (replace-match ".\n \\1" )))))

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy JavaScript in Depth

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


ELisp Examples

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples

Misc