Subject: bug#11531: 24.1.50; electric-pair-mode needs to detect apostrophes in strings or comments

From: Simon Law <[email-masked]>
Date: Mon, 11 Jun 2012 17:28:17 -0400

I now use the following workaround, in order to always pair when the
region is active:

(defadvice electric-pair-post-self-insert-function (around
                                                    electric-pair-apostrophe
                                                    activate)
  "Fix electric-pair to handle apostrophes inside strings or comments"
  (if (use-region-p)
      ;; Always pair if the region is active
      ad-do-it
   (let* ((quick-syntax-info (syntax-ppss))
          (inside-string (fourth quick-syntax-info))
          (inside-comment (fifth quick-syntax-info)))
     (if (not (eq last-command-event ?\'))
         ;; Only deal with single-quote characters
         ad-do-it
       (let* ((char-before-insert (char-before (1- (point))))
              (char-before-syntax (and char-before-insert
                                       (char-syntax char-before-insert))))
         ;; We want the character before the self-insert-command
         (if (and (or inside-string inside-comment)
                  (eq char-before-syntax ?w))
             ;; Single-quotes inside a string or comment, and immediately
             ;; following a word, are actually apostrophes and should not
             ;; be paired.
             t
           ad-do-it))))))

-- 
Cheers,
Simon - http://ca.linkedin.com/in/sfllaw/