GNU bug report logs - #11531
24.1.50; electric-pair-mode needs to detect apostrophes in strings or comments

Previous Next

Package: emacs;

Reported by: Simon Law <sfllaw <at> sfllaw.ca>

Date: Mon, 21 May 2012 04:35:02 UTC

Severity: normal

Found in versions 24.1.50, 24.3

Fixed in version 24.5

Done: Noam Postavsky <npostavs <at> users.sourceforge.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Simon Law <sfllaw <at> sfllaw.ca>
To: 11531 <at> debbugs.gnu.org
Subject: bug#11531: 24.1.50; electric-pair-mode needs to detect apostrophes in strings or comments
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/




This bug report was last modified 9 years and 66 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.