Elisp: 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.

(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://ergoemacs.org/emacs/emacs_period_to_line_end.html'
Version 2020-11-25 2021-07-04"
  (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")
        (backward-char )
        (setq $p2 (point))))
      (narrow-to-region $p1 $p2)
      (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 ?> ))
            (insert ".")))
        (forward-char )))))

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