Emacs: Bracket CAPITALIZED WORDS 🚀

By Xah Lee. Date: . Last updated: .

This command add angle quotation marks around CAPITALIZED WORDS, on selection or current text block.

This is useful if you write lisp documentation.

(defun xah-bracket-capitalized-words ()
  "Add ‹› to CAPITALIZED WORDS, on selection or current text block.
Example:
Change value in PLIST of PROP to VAL
becomes
Change value in ‹PLIST› of ‹PROP› to ‹VAL›

If the word already has bracket, or between >< , do nothing.

2021-04-10 command name was xah-bracket-caps.

URL `http://xahlee.info/emacs/emacs/elisp_bracket_caps.html'
Version: 2020-04-19 2021-09-21 2022-06-18"
  (interactive)
  (let* ((xbds (xah-get-bounds-of-thing-or-region 'block))
         (xp1 (car xbds)) (xp2 (cdr xbds))
         (case-fold-search nil))
    (save-restriction
      (narrow-to-region xp1 xp2)
      (goto-char (point-min))
      (while (re-search-forward "\\b\\([A-Z][-_A-Z0-9]+\\)\\b" nil t)
        (goto-char (match-end 0))
        (when (and (not (eq (char-after) ?›))
                   (not (eq (char-after) ?<)))
          (insert "›")
          (goto-char (match-beginning 0))
          (insert "‹"))
        ;; (replace-match (concat "‹" (match-string-no-properties 1) "›") t )
        ))))

requires package Emacs: xah-get-thing.el