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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11531 in the body.
You can then email your comments to 11531 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#11531; Package emacs. (Mon, 21 May 2012 04:35:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Simon Law <sfllaw <at> sfllaw.ca>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 21 May 2012 04:35:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Simon Law <sfllaw <at> sfllaw.ca>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.1.50;
	electric-pair-mode needs to detect apostrophes in strings or comments
Date: Mon, 21 May 2012 00:33:47 -0400
Reproduction steps:

$ emacs -Q
M-x js-mode
M-x electric-pair-mode
Type: // Simon's comment
Press RET
Type "Simon's string"
Press RET

Expected result:

// Simon's comment
"Simon's string"

Actual result:

// Simon's comment'
"Simon's string'"

Notes:

Inside a comment or string, in a programming mode, we can try to detect
apostophes. An apostrophe is likely if you've inserted a single-quote
that immediately follows a word character.

Here is my workaround:

(defadvice electric-pair-post-self-insert-function (around
                                                    electric-pair-apostrophe
                                                    activate)
  "Fix electric-pair to handle apostrophes inside strings or comments"
  (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)))))

In GNU Emacs 24.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.2.0)
 of 2012-05-10 on charichuelo, modified by Debian
 (emacs-snapshot package, version 2:20120510-1~ppa1~oneiric1)
Windowing system distributor `The X.Org Foundation', version 11.0.11004000
Configured using:
 `configure '--build' 'x86_64-linux-gnu' '--host' 'x86_64-linux-gnu'
 '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
 '--localstatedir=/var' '--infodir=/usr/share/info'
 '--mandir=/usr/share/man' '--with-pop=yes'
 '--enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/24.1.50/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.1.50/site-lisp:/usr/share/emacs/site-lisp'
 '--without-compress-info' '--with-crt-dir=/usr/lib/x86_64-linux-gnu/'
 '--with-x=yes' '--with-x-toolkit=gtk3' '--with-imagemagick=yes'
 'build_alias=x86_64-linux-gnu' 'host_alias=x86_64-linux-gnu'
 'CFLAGS=-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2' 'LDFLAGS=-g
 -Wl,--as-needed -znocombreloc' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: en_CA.UTF-8
  value of $LC_CTYPE: en_CA.UTF-8
  value of $LC_MESSAGES: en_CA.UTF-8
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_CA.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Javascript

Minor modes in effect:
  electric-pair-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
M-x j s - m o d e <return> M-x e l e c t r i c - p 
a i r - m o d e <return> / / SPC S i m o n ' s SPC 
c o m m e n t C-e <return> " S i m o n ' s SPC s t 
r i n g C-n M-x r e p o r t - e m a c s - b u g
<return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Electric-Pair mode enabled
byte-code: End of buffer

Load-path shadows:
/usr/share/emacs/24.1.50/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils cus-start cus-load electric js byte-opt bytecomp
byte-compile cconv macroexp json imenu thingatpt cc-mode cc-fonts
easymenu cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel
x-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list
newcomment lisp-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer loaddefs button faces cus-face files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11531; Package emacs. (Mon, 11 Jun 2012 21:32:01 GMT) Full text and rfc822 format available.

Message #8 received at 11531 <at> debbugs.gnu.org (full text, mbox):

From: Simon Law <sfllaw <at> sfllaw.ca>
To: 11531 <at> debbugs.gnu.org
Subject: Re: 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/




bug Marked as found in versions 24.3. Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Thu, 09 Jun 2016 23:20:02 GMT) Full text and rfc822 format available.

bug Marked as fixed in versions 24.5. Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Thu, 09 Jun 2016 23:20:02 GMT) Full text and rfc822 format available.

Reply sent to Noam Postavsky <npostavs <at> users.sourceforge.net>:
You have taken responsibility. (Thu, 09 Jun 2016 23:21:02 GMT) Full text and rfc822 format available.

Notification sent to Simon Law <sfllaw <at> sfllaw.ca>:
bug acknowledged by developer. (Thu, 09 Jun 2016 23:21:02 GMT) Full text and rfc822 format available.

Message #17 received at 11531-done <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: 11531-done <at> debbugs.gnu.org
Subject: Fwd: 24.1.50; electric-pair-mode needs to detect apostrophes in
 strings or comments
Date: Thu, 9 Jun 2016 19:20:20 -0400
Seems to have been fixed in 24.5 at the latest




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 08 Jul 2016 11:24:04 GMT) Full text and rfc822 format available.

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.