1

I'm enjoying 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 M-w (kill-ring-save), but the region seems to be represented as an "overlay," and there is no function to capture it.

1

Try this:

  • If your cursor is after the closing paren: M-- C-M-SPC

  • If your cursor is before the opening paren: C-M-SPC

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.)

0

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" (interactive) (if (and (boundp 'show-paren--overlay) (overlay-end show-paren--overlay)) (kill-ring-save (overlay-start show-paren--overlay) (overlay-end show-paren--overlay)) (user-error "No parentheses are being shown right now")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.