I have the following custom implementation of insert-pair
:
(defun *-insert-pair (&optional arg open close)
"Wrap next ARG sexps in parentheses.
If there is no next sexp, insert a new pair of parentheses."
(interactive "p")
(let ((arg (or arg 1))
(exists-next-sexp t))
(save-excursion
(condition-case nil
(forward-sexp)
(scan-error (setq exists-next-sexp nil))))
(if exists-next-sexp
(insert-pair arg open close)
(insert-pair nil open close))))
However, I don't like the use of the boolean var exist-next-sexp
. Is there a more idiomatic way to write this so I can get rid of it?