Emacs: Remove Punctuation Extra Spaces 🚀
Remove Punctuation Trailing Redundant Spaces
Here's helpful command to remove redundant spaces after punctuation.
- In English text, the convention is to have 1 space after punctuation (sometimes 2, after the Full Stop sign).
- In Chinese text, the convention is to have no space after punctuation.
(defun xah-remove-punctuation-trailing-redundant-space (Begin End) "Remove redundant whitespace after punctuation. Works on current line or text selection. When called in emacs lisp code, the Begin End are cursor positions for region. See also `xah-convert-english-chinese-punctuation'. URL `http://xahlee.info/emacs/emacs/elisp_convert_chinese_punctuation.html' Version: 2015-08-22" (interactive (if (use-region-p) (list (region-beginning) (region-end)) (list (line-beginning-position) (line-end-position)))) (require 'xah-replace-pairs) (xah-replace-regexp-pairs-region Begin End [ ;; clean up. Remove extra space. [" +," ","] [", +" ", "] ["? +" "? "] ["! +" "! "] ["\\. +" ". "] ;; fullwidth punctuations [", +" ","] ["。 +" "。"] [": +" ":"] ["? +" "?"] ["; +" ";"] ["! +" "!"] ["、 +" "、"] ] t t))
requires package Emacs: xah-replace-pairs.el