Elisp: Bracket CAP WORDS

By Xah Lee. Date: .

Here's a command to add brackets to all CAPITAL WORDS.

(defun xah-bracket-caps ()
  "add ‹› to CAPITALIZED WORDS, on selection or current text block.

 Change value in PLIST of PROP to VAL
 Change value in ‹PLIST› of ‹PROP› to ‹VAL›

URL `http://ergoemacs.org/emacs/elisp_bracket_caps.html'
Version 2020-04-19, 2021-01-07"
  (let ($p $p2 (case-fold-search nil))
    (if (use-region-p)
        (setq $p1 (region-beginning) $p2 (region-end))
        (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)))))
      (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 Examples

ELisp Write Major Mode

ELisp Examples

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples