Emacs: Change to Title Case π
Here's emacs command to change letter case by title convention.
For example, βA Tale of Two Citiesβ, not βA Tale Of Two Citiesβ.
put this in your Emacs Init File:
(defun xah-title-case-region-or-line (&optional Begin End) "Title case text between nearest brackets, or current line or selection. Capitalize first letter of each word, except words like {to, of, the, a, in, or, and}. If a word already contains cap letters such as HTTP, URL, they are left as is. When called in a elisp program, Begin End are region boundaries. URL `http://xahlee.info/emacs/emacs/elisp_title_case_text.html' Version: 2017-01-11 2021-03-30 2021-09-19" (interactive) (let* ((xskipChars "^\"<>(){}[]βββββΉβΊΒ«Β»γγγγγγγγγγγγγγ") (xp0 (point)) (xp1 (if Begin Begin (if (region-active-p) (region-beginning) (progn (skip-chars-backward xskipChars (line-beginning-position)) (point))))) (xp2 (if End End (if (region-active-p) (region-end) (progn (goto-char xp0) (skip-chars-forward xskipChars (line-end-position)) (point))))) (xstrPairs [ [" A " " a "] [" An " " an "] [" And " " and "] [" At " " at "] [" As " " as "] [" By " " by "] [" Be " " be "] [" Into " " into "] [" In " " in "] [" Is " " is "] [" It " " it "] [" For " " for "] [" Of " " of "] [" Or " " or "] [" On " " on "] [" Via " " via "] [" The " " the "] [" That " " that "] [" To " " to "] [" Vs " " vs "] [" With " " with "] [" From " " from "] ["'S " "'s "] ["'T " "'t "] ])) (save-excursion (save-restriction (narrow-to-region xp1 xp2) (upcase-initials-region (point-min) (point-max)) (let ((case-fold-search nil)) (mapc (lambda (xx) (goto-char (point-min)) (while (search-forward (aref xx 0) nil t) (replace-match (aref xx 1) t t))) xstrPairs))))))