show-paren-mode using the "expression" style, which highlights a parenthesized region in a contrasting color. I'd like to define an Emacs Lisp function that could capture the region into the kill ring, as in
kill-ring-save), but the region seems to be represented as an "overlay," and there is no function to capture it.
If your cursor is after the closing paren:
If your cursor is before the opening paren:
C-M-SPC is bound by default to
mark-sexp. It selects the next N sexps. With a negative prefix arg it selects the previous abs(N) sexps.
(Oh, and it doesn't matter whether
show-paren-mode is on or off.)
Using the source, I came up with this function:
(defun kill-ring-save-paren-overlay ()
"Save the current 'show-paren-mode' overlay into the kill rang"
(if (and (boundp 'show-paren--overlay) (overlay-end show-paren--overlay))
(kill-ring-save (overlay-start show-paren--overlay)
(user-error "No parentheses are being shown right now")))