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?
(insert-pair (and exists-next-sexp arg) open close)
, which makes clear thatinsert-pair
is used in any case. 2. Don't bother with a secondARG
variable (confusing to use the same name, and nothing gained). Just(setq arg (or arg 1)
.(setq exists-next-sexp nil)
with(setq arg nil)
.