I use the code below and bind
Example usage : with point on
(, I hit
M-D [ and the
() pair becomes a
 pair. If you hit
M-D RET instead, the pair will be removed.
This code uses the syntax table, which means that for some pairs you'll have to specify the closing paren yourself. e.g. in html-mode,
() can be replaced by
<> by hitting
M-D <. However, in many modes
<> isn't a recognized pair, and
M-D < will say "Don't know how to close <". You can then you just type
(defun yf/replace-or-delete-pair (open)
"Replace pair at point by OPEN and its corresponding closing character.
The closing character is lookup in the syntax table or asked to
the user if not found."
(format "Replacing pair %c%c by (or hit RET to delete pair):"
(if (memq open '(?\n ?\r))
(let ((close (cdr (aref (syntax-table) open))))
(when (not close)
(format "Don't know how to close character %s (#%d) ; please provide a closing character: "
(single-key-description open 'no-angles)
(yf/replace-pair open close))))
(defun yf/replace-pair (open close)
"Replace pair at point by respective chars OPEN and CLOSE.
If CLOSE is nil, lookup the syntax table. If that fails, signal
(let ((close (or close
(cdr-safe (aref (syntax-table) open))
(error "No matching closing char for character %s (#%d)"
(single-key-description open t)
(insert-pair 1 open close))