Emacs: Select Text Between Quotes šŸš€

By Xah Lee. Date: .

Select Text between Quotes/Brackets

Select text inside quotes is one of the most frequently needed operation in programing languages code.

put this in your Emacs Init File:

(defvar xah-brackets '("ā€œā€" "()" "[]" "{}" "<>" "ļ¼œļ¼ž" "ļ¼ˆļ¼‰" "[]" "ļ½›ļ½" "⦅⦆" "怚怛" "ā¦ƒā¦„" "‹›" "«»" "怌怍" "怈怉" "怊怋" "怐怑" "怔怕" "ā¦—ā¦˜" "怎怏" "怖怗" "怘怙" "「」" "⟦⟧" "⟨⟩" "⟪⟫" "⟮⟯" "⟬⟭" "āŒˆāŒ‰" "āŒŠāŒ‹" "ā¦‡ā¦ˆ" "ā¦‰ā¦Š" "ā›āœ" "āāž" "āØā©" "āŖā«" "ā“āµ" "ā¬ā­" "ā®āÆ" "ā°ā±" "ā²ā³" "〈〉" "⦑⦒" "⧼⧽" "ļ¹™ļ¹š" "ļ¹›ļ¹œ" "ļ¹ļ¹ž" "⁽⁾" "ā‚ā‚Ž" "ā¦‹ā¦Œ" "ā¦ā¦Ž" "ā¦ā¦" "⁅⁆" "⸢⸣" "⸤⸄" "āŸ…āŸ†" "⦓⦔" "⦕⦖" "⸦⸧" "āøØāø©" "⦅⦆")
 "A list of strings, each element is a string of 2 chars, the left bracket and a matching right bracket.
Used by `xah-select-text-in-quote' and others.
Version 2023-07-31")

(defconst xah-left-brackets
  (mapcar (lambda (x) (substring x 0 1)) xah-brackets)
  "List of left bracket chars. Each element is a string.")

(defconst xah-right-brackets
  (mapcar (lambda (x) (substring x 1 2)) xah-brackets)
  "List of right bracket chars. Each element is a string.")

(defun xah-select-text-in-quote ()
  "Select text between the nearest left and right delimiters.
Delimiters here includes QUOTATION MARK, GRAVE ACCENT, and anything in `xah-brackets'.
This command ignores nesting. For example, if text is
怌(a(b)cā–®)怍
the selected char is 怌c怍, not 怌a(b)c怍.

URL `http://xahlee.info/emacs/emacs/emacs_select_quote_text.html'
Version: 2020-11-24 2023-07-23 2023-11-14"
  (interactive)
  (let ((xskipChars (concat "^\"`" (mapconcat #'identity xah-brackets ""))))
    (skip-chars-backward xskipChars)
    (push-mark (point) t t)
    (skip-chars-forward xskipChars)))

Emacs, Work with Brackets