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: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Simon Law <sfllaw <at> sfllaw.ca>
Subject: bug#11531: closed (Fwd: 24.1.50; electric-pair-mode needs to
 detect apostrophes in strings or comments)
Date: Thu, 09 Jun 2016 23:21:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 11531 <at> debbugs.gnu.org.

-- 
11531: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11531
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
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

[Message part 3 (message/rfc822, inline)]
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)



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.