Subject: bug#16085: 24.3.50; electric-pair-mode and cua-mode clash when autowrapping region

From: [email-masked] (João Távora)
Date: Sat, 07 Dec 2013 19:26:34 +0000

Hello maintainers,

    emacs -Q
    M-x cua-mode
    M-x electric-pair-mode
    insert foo
    select region "foo"
    press "("
    should get "(foo)", get ")(" instead.

This is a problem I solved in my third-party autopair.el library using
this horrible code

    (defun autopair--should-autowrap ()
      (and autopair-mode
           (not (eq this-command 'autopair-backspace))
           (symbolp this-command)
           (string-match "^autopair" (symbol-name this-command))
           (autopair--calculate-wrap-action)))
     
    (defadvice cua--pre-command-handler-1 (around autopair-override activate)
      "Don't actually do anything if autopair is about to autowrap. "
      (unless (autopair--should-autowrap) ad-do-it))
     
    ;; aparently not needed for electric.el since it works ok with delete-selectrion-mode
    ;; 
    ;; (defadvice delete-selection-pre-hook (around autopair-override activate)
    ;;   "Don't actually do anything if autopair is  about to autowrap. "
    ;;   (unless (autopair--should-autowrap) ad-do-it))

Thanks,
João