Emacs Lisp: 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›

2021-04-10 command name was xah-bracket-caps.
URL `http://xahlee.info/emacs/emacs/elisp_bracket_caps.html'
Version 2020-04-19, 2021-04-10"
  (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 )))))
ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Elisp Examples

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples

Misc