Emacs: Add Period to Line Ends 🚀

By Xah Lee. Date: . Last updated: .

This command add a period to each end of line in current text lock. This is a useful when you copy text from discord or twitter to your blog.

put this in your Emacs Init File:

(defun xah-add-period-to-line-end ()
  "Add a period to each end of line that does not have one.
Work on current paragraph if there is no selection.

URL `http://xahlee.info/emacs/emacs/emacs_period_to_line_end.html'
Version: 2020-11-25 2021-08-17 2022-01-10"
  (interactive)
  (let (xp1 xp2)
    (let ((xbds (xah-get-bounds-of-block-or-region))) (setq xp1 (car xbds) xp2 (cdr xbds)))
    (save-restriction
      (narrow-to-region xp1 xp2)
      (goto-char (point-max))
      (insert "\n")
      (goto-char (point-min))
      (while (search-forward "\n" nil "move")
        (backward-char)
        (let ((charX (char-before)))
          (if (or (eq charX ?\.) (eq charX ?!) (eq charX ??) (eq charX ?\n) (eq charX ?>))
              nil
            (insert ".")))
        (forward-char))
      (goto-char (point-max))
      (when (eq (char-before) ?\n) (delete-char -1)))))

requires package Emacs: xah-get-thing.el 📦

Emacs, Reformat Sentences