unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Simon Law <sfllaw@sfllaw.ca>
To: 11531@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	[thread overview]
Message-ID: <CABMJL3+qbVK0+W1i6S4L0mV5iPaOfVhjuQLC89V-gyPRuuYMtg@mail.gmail.com> (raw)
In-Reply-To: <877gw6qhjo.fsf@sfllaw.ca>

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/





      reply	other threads:[~2012-06-11 21:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-21  4:33 bug#11531: 24.1.50; electric-pair-mode needs to detect apostrophes in strings or comments Simon Law
2012-06-11 21:28 ` Simon Law [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABMJL3+qbVK0+W1i6S4L0mV5iPaOfVhjuQLC89V-gyPRuuYMtg@mail.gmail.com \
    --to=sfllaw@sfllaw.ca \
    --cc=11531@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).