Function: electric-pair-inhibit-if-helps-balance
electric-pair-inhibit-if-helps-balance is a byte-compiled function
defined in elec-pair.el.gz.
Signature
(electric-pair-inhibit-if-helps-balance CHAR)
Documentation
Return non-nil if auto-pairing of CHAR unbalances delimiters.
Works by first removing the character from the buffer, then doing some list calculations, finally restoring the situation as if nothing happened.
Source Code
;; Defined in /usr/src/emacs/lisp/elec-pair.el.gz
(defun electric-pair-inhibit-if-helps-balance (char)
"Return non-nil if auto-pairing of CHAR unbalances delimiters.
Works by first removing the character from the buffer, then doing
some list calculations, finally restoring the situation as if nothing
happened."
(pcase (electric-pair-syntax-info char)
(`(,syntax ,pair ,_ ,s-or-c)
(catch 'done
;; FIXME: modify+undo is *very* tricky business. We used to
;; use `delete-char' followed by `insert', but this changed the
;; position some markers. The real fix would be to compute the
;; result without having to modify the buffer at all.
(atomic-change-group
;; Don't use `delete-char'; that may modify the head of the
;; undo list.
(delete-region (point) (1- (point)))
(throw
'done
(cond ((eq ?\( syntax)
(let* ((pair-data
(electric-pair--balance-info 1 s-or-c))
(outermost (cdr pair-data)))
(cond ((car outermost)
nil)
(t
(eq (cdr outermost) pair)))))
((eq syntax ?\")
(electric-pair--unbalanced-strings-p char)))))))))