Elisp: Bracket ALL-CAPS Words

By Xah Lee. Date: .

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

This is useful if you write lisp documentation.

(defun xah-bracket-caps ()
  "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›

URL `http://ergoemacs.org/emacs/elisp_bracket_allcaps_words.html'
Version 2020-04-19, 2020-12-08"
  (interactive)
  (let ($p $p2 (case-fold-search nil))
    (if (use-region-p)
        (setq $p1 (region-beginning) $p2 (region-end))
      (save-excursion
        (if (re-search-backward "\n[ \t]*\n" nil "move")
            (progn (re-search-forward "\n[ \t]*\n")
                   (setq $p1 (point)))
          (setq $p1 (point)))
        (if (re-search-forward "\n[ \t]*\n" nil "move")
            (progn (re-search-backward "\n[ \t]*\n")
                   (setq $p2 (point)))
          (setq $p2 (point)))))
    (save-restriction
      (narrow-to-region $p1 $p2)
      (goto-char (point-min))
      (while (re-search-forward "\\b\\([A-Z][-A-Z0-9]+\\)\\b" nil t)
        (replace-match (concat "‹" (match-string 1) "›") t )))))

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy JavaScript in Depth

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


ELisp Examples

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples

Misc