Subject: 28.0.50; sql-mode gets confused about string literals

From: Dale Sedivec <[email-masked]>
Date: Sun, 15 Nov 2020 00:37:08 -0600

I think `syntax-ppss' has started returning incorrect information about
apostrophe-delimited strings in sql-mode in master.  I am actually on
native-comp with this afternoon's master merged in myself, but I am
fairly confident you can reproduce this on master, nothing to do with
native-comp.

Steps to reproduce:

1. emacs -Q

2. Evaluate the following in *scratch*:

      (let ((buf (generate-new-buffer "sql")))
        (switch-to-buffer buf)
        (sql-mode)
        (insert "select '''")
        (goto-char 1)
        (delete-region 1 8)
        (goto-char (point-max)))

   Point should now be at the end of an `sql-mode' buffer containing
   "'''" (three apostrophes).

4. Press backspace to erase the third apostrophe.

5. M-: (nth 3 (syntax-ppss)) RET

Expected result: fourth element of syntax-ppss, the delimiter character
for the current string, is nil, since we are no longer in a string

Observed result: fourth element is ?' (39), indicating that point is
still inside a string

My first guess is that this is related to commit 289d6b2265e and #40231.

I came across this while trying to get back something resembling the
behavior of `electric-pair-mode', and in particular
`electric-pair-skip-self', as it was prior to 289d6b2265e.  I'm almost
there, but I ran into the above bug and got stuck.

Kind regards,
Dale

In GNU Emacs 28.0.50 (build 1, x86_64-apple-darwin19.6.0, NS appkit-1894.60 Version 10.15.7 (Build 19H15))
of 2020-11-14 built on dale
Repository revision: 99cbb313a3fd037b55ad3700635f607f56b0fa3e
Repository branch: feature/native-comp
Windowing system distributor 'Apple', version 10.3.1894
System Description:  Mac OS X 10.15.7

Configured using:
'configure --without-x --with-modules --with-threads --with-xwidgets
--with-zlib --with-xml2 --with-json --with-cairo --with-gnutls
--with-xpm --with-jpeg --with-tiff --with-gif --with-png --with-rsvg
--with-nativecomp --with-ns --enable-ns-self-contained 'CFLAGS=-O2
-I/opt/local/include/gcc10' LDFLAGS=-L/opt/local/lib/gcc10'

Configured features:
PNG RSVG GLIB NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS
XIM NS MODULES NATIVE_COMP THREADS XWIDGETS JSON PDUMPER LCMS2

Important settings:
  value of $LC_COLLATE: C
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: SQL[ANSI]

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-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

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils sql auth-source
eieio eieio-core eieio-loaddefs password-cache json map view thingatpt
comint ansi-color ring comp warnings subr-x rx cl-seq cl-macs cl-extra
help-mode easymenu seq byte-opt gv cl-loaddefs cl-lib bytecomp
byte-compile cconv tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/ns-win ns-win ucs-normalize mule-util
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face pcase macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads xwidget-internal kqueue cocoa
ns lcms2 multi-tty make-network-process nativecomp emacs)

Memory information:
((conses 16 83359 5743)
(symbols 48 8493 1)
(strings 32 23422 3672)
(string-bytes 1 888517)
(vectors 16 16669)
(vector-slots 8 316241 15044)
(floats 8 29 23)
(intervals 56 234 0)
(buffers 992 13))