 
 (defun autopair-extra-skip-close-maybe ()
   (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
   (when (autopair-extra-skip-p)
-    (setq autopair-action (list 'closing last-input-event (point))))
+    (setq autopair-action (list 'closing autopair-inserted (point))))
   (autopair-fallback))
 (put 'autopair-extra-skip-close-maybe 'function-documentation
      '(concat "Insert or possibly skip over a (and extra) closing delimiter.\n\n"

                             pair-list))
                   (remove-if-not #'listp autopair-extra-pairs)))))))

(defun autopair-set-wrapping-action ()
  (when mark-active
    (save-excursion
      (let* ((region-before (cons (region-beginning)
                                  (region-end)))
             (point-before (point))
             (start-syntax (syntax-ppss (car region-before)))
             (end-syntax   (syntax-ppss (cdr region-before))))
        (when (and (eq (nth 0 start-syntax) (nth 0 end-syntax))
                   (eq (nth 3 start-syntax) (nth 3 end-syntax)))
          (setq autopair-wrap-action (list 'wrap (or (second autopair-action)
                                                     (autopair-find-pair last-input-event))
                                           point-before
                                           region-before)))))))

(defun autopair-fallback (&optional fallback-keys)
  (let* ((autopair-emulation-alist nil)
         (beyond-cua (let ((cua--keymap-alist nil))
                       (or (key-binding (this-single-command-keys))
                           (key-binding fallback-keys))))
         (beyond-autopair (or (key-binding (this-single-command-keys))
                              (key-binding fallback-keys))))
    (when autopair-autowrap
      (autopair-set-wrapping-action))
    
    (setq this-original-command beyond-cua)
    ;; defer to "paredit-mode" if that is installed and running

                     (save-excursion
                       (let ((pos-pair (autopair-up-list syntax-info))
                             (prev-point (point-max))
                             (expected-closing (autopair-find-pair autopair-inserted)))
                         (condition-case err
                             (progn
                               (while (not (eq prev-point (point)))
