+(defcustom electric-pair-inhibit-predicate
+ #'electric-pair-default-inhibit
+ "Predicate to prevent insertion of a matching pair.
+The function is called with a single char (the opening char just inserted).
+If it returns non-nil, then `electric-pair-mode' will not insert a matching
+closer."
+ :version "24.4"
+ :type '(choice
+ (const :tag "Default" electric-pair-default-inhibit)
+ (const :tag "Always pair" ignore)
+ function))
+
+(defun electric-pair-default-inhibit (char)
+ (or
+ ;; I find it more often preferable not to pair when the
+ ;; same char is next.
+ (eq char (char-after))
+ ;; Don't pair up when we insert the second of "" or of ((.
+ (and (eq char (char-before))
+ (eq char (char-before (1- (point)))))
+ ;; I also find it often preferable not to pair next to a word.
+ (eq (char-syntax (following-char)) ?w)))
+
+(defun electric-pair-syntax (command-event)
+ (let ((x (assq command-event electric-pair-pairs)))
+ (cond
+ (x (if (eq (car x) (cdr x)) ?\" ?\())
+ ((rassq command-event electric-pair-pairs) ?\))
+ ((nth 8 (syntax-ppss))
+ (with-syntax-table text-mode-syntax-table (char-syntax command-event)))
+ (t (char-syntax command-event)))))
+
+(defun electric-pair--insert (char)
+ (let ((last-command-event char)
+ (blink-matching-paren nil)
+ (electric-pair-mode nil))
+ (self-insert-command 1)))
+