Emacs: Add Period to Line Ends ðŸ’
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' Created: 2020-11-25 Version: 2025-03-26" (interactive) (let (xbeg xend) (seq-setq (xbeg xend) (if (region-active-p) (list (region-beginning) (region-end)) (list (save-excursion (if (re-search-backward "\n[ \t]*\n" nil 1) (match-end 0) (point))) (save-excursion (if (re-search-forward "\n[ \t]*\n" nil 1) (match-beginning 0) (point)))))) (save-restriction (narrow-to-region xbeg xend) (goto-char (point-max)) (insert "\n") (goto-char (point-min)) (while (search-forward "\n" nil 1) (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)))))