Elisp: 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://ergoemacs.org/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 )))))

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


ELisp Examples

Xah Commands

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples

Misc