all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Alan Mackenzie <acm@muc.de>, emacs-devel <emacs-devel@gnu.org>
Subject: Fwd: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode
Date: Tue, 2 Jul 2019 16:27:06 +0100	[thread overview]
Message-ID: <CALDnm53=WN2S5Ehz1Tt3On87ERAW-hNexjqymYsC-meA=5vEAQ@mail.gmail.com> (raw)
In-Reply-To: <CALDnm51Hi10KMqYneWBamNL4sNdzHEz6_NasGk=oR_y-=1Y7nQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3817 bytes --]

On Tue, Jul 2, 2019 at 2:16 PM Alan Mackenzie <acm@muc.de> wrote:

> Hello João and Emacs.

Hello Alan and Emacs,

> This is a follow up bug to bug #36423: 27.0.50; electric-pair-mode not
> working properly depending of file content.

[Did you mean to copy bug-gnu-emacs@gnu.org, or emacs-devel@gnu.org?
I'm assuming the latter and correcting. And sorry for the duplicate reply
Alan.]

> Start the Emacs master (up to date state as of 2019-07-02T14:30 +0000)
> with emacs -Q, put the following in a C++ Mode buffer and enable
> electric-pair-mode:
>
> "foo\n
>
> .  Type a " at the end of foo.  electric-pair-mode wrongly inserts two
> "s.
>
> Diagnosis: electric-pair--unbalanced-strings-p works after the (single)
> newly typed " has been stripped from the buffer.  It attempts to
> determine whether there are any open strings after the point of
> insertion.  It does this by using parse-partial-sexp, and checks (nth 3
> <result>) as evidence of an open string.

I'm afraid this is a (another?) direct consequence of the NL-terminated
strings feature that you introduced more than one year ago.  If you
remember, this had various consequences vis-a-vis balancing,
broke a test (one that I disabled in the expectation that a fix would be
made available, which I don't think happened). Here are some points of
that thread:

https://lists.gnu.org/archive/html/emacs-devel/2018-06/msg00551.html
https://lists.gnu.org/archive/html/emacs-devel/2018-06/msg00580.html

I think I made my views clear back then: NL-terminated strings are a
misfeature. The only argument _for_ them, that they mimic what some
compilers do, is very weak because (1) the code is invalid in both
situations (not in any way "slightly less" invalid in any of them) and
(2) compilers don't edit code and so have different requirements.

The arguments _against_ NL-terminated strings is that they (1) break
longstanding features such as sexp-based navigation (e.g. `up-list`
and friends) for modes such say, `js-mode` and (2) break features
that expect this to work, most notably electric-pair-mode.

Moving forward:

1. We can consider that electric-pair-mode is doing the right thing.
Indeed if NL is indeed terminating a string, then quote balance has been
maintained after the double quote insertion, i.e. it has not worsened.
That is the general contract of  `electric-pair-preserve-balance`.

2.The NL-terminated string feature is removed (or, if you prefer, is
made disableable). This would restore the behaviour that most users
would expect coming over, from say python-mode or js-mode. Perhaps
it can already be disabled with a couple of lines of emacs-lisp tweaking
the syntax-table.

3. Someone comes up with a suitable indirection that doesn't involve
hardcoding `cc-mode` in elec-pair.el.  That indirection would
presumably do what you want for modes `cc-mode` derived
from cc-mode.

4. Someone reinvents electric-pair-mode in cc-model.el.
Let's not do this.

I prefer 2.

Thanks,
João



>


>
> This does not work in CC Mode, since although there is an open string
> marker (with a string fence syntax-table property on it) this is
> "closed" (from parse-partial-sexp's point of view) by the string fence
> property on the newline at the end of the line.
> electric-pair--unbalanced-strings-p thus returns the wrong result.
>
> A more suitable algorithm might look something like this: check whether
> the newly inserted " has a string fence syntax-table text property.
> (Its insertion will have already triggered the before- and
> after-change-functions which set this property.)  If so, there is an
> open string.  Of course, this only applies to CC Mode modes.
>
> --
> Alan Mackenzie (Nuremberg, Germany).



--
João Távora

[-- Attachment #2: Type: text/html, Size: 5293 bytes --]

  parent reply	other threads:[~2019-07-02 15:27 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-02 13:16 bug#36474: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode Alan Mackenzie
     [not found] ` <CALDnm51Hi10KMqYneWBamNL4sNdzHEz6_NasGk=oR_y-=1Y7nQ@mail.gmail.com>
2019-07-02 15:27   ` João Távora [this message]
2019-07-02 16:04   ` Alan Mackenzie
2019-07-02 17:22     ` João Távora
2019-07-02 17:22     ` João Távora
2019-07-02 18:28       ` bug#36474: " Alan Mackenzie
2019-07-02 21:11         ` Stefan Monnier
2019-07-03  9:28         ` João Távora
2019-07-03 10:58           ` Alan Mackenzie
2019-07-03 13:07             ` Dmitry Gutov
2019-07-03 13:32               ` Alan Mackenzie
2019-07-03 14:25                 ` Dmitry Gutov
2019-07-03 15:58                 ` Eli Zaretskii
2019-07-03 20:54                   ` Alan Mackenzie
2019-07-04  2:33                     ` Eli Zaretskii
2019-07-04  1:36                 ` Richard Stallman
2019-07-03 13:33               ` Eli Zaretskii
2019-07-03 13:35               ` João Távora
2019-07-03 13:31             ` João Távora
2019-07-03 18:25               ` Kévin Le Gouguec
2019-07-04  0:52                 ` João Távora
2019-07-04  6:17                   ` Kévin Le Gouguec
2019-07-04 15:05               ` Alan Mackenzie
2019-07-04 15:50                 ` João Távora
2019-07-04 16:58               ` [PATCH] " Alan Mackenzie
2019-07-04 18:45                 ` João Távora
2019-07-04 19:01                   ` Alan Mackenzie
2019-07-04 21:44                     ` João Távora
2019-07-08 10:05                       ` Alan Mackenzie
2019-07-08 12:10                         ` João Távora
2019-07-08 15:49                         ` Stefan Monnier
2019-07-08 16:33                           ` Stefan Monnier
2019-07-08 17:24                             ` Alan Mackenzie
2019-07-08 17:32                               ` Stefan Monnier
2019-07-08 16:45                           ` Alan Mackenzie
2019-07-08 17:29                             ` Stefan Monnier
2019-07-08 18:05                               ` Alan Mackenzie
2019-07-08 20:59                                 ` Stefan Monnier
2019-07-09  6:41                                   ` Clément Pit-Claudel
2019-07-09  9:06                                     ` João Távora
2019-07-09  9:23                                       ` João Távora
2019-07-09  9:52                                         ` Alan Mackenzie
2019-07-09 10:54                                           ` João Távora
2019-07-09 11:18                                             ` João Távora
2019-07-09 15:18                                             ` Dmitry Gutov
2019-07-09 15:40                                               ` contextual refontification (was: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode) Stefan Monnier
2019-07-10  9:32                                                 ` João Távora
2019-07-09 15:43                                               ` [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode João Távora
2019-07-09 15:31                                             ` Alan Mackenzie
2019-07-09 16:14                                               ` João Távora
2019-07-09 12:33                                       ` Clément Pit-Claudel
2019-07-09 14:28                                         ` João Távora
2019-07-09 16:05                                           ` Clément Pit-Claudel
2019-07-09 16:32                                             ` João Távora
2019-07-09 17:09                                               ` João Távora
2019-07-09 13:45                                     ` Stefan Monnier
2019-07-09 16:00                                   ` Alan Mackenzie
2019-07-09 17:11                                     ` Stefan Monnier
2019-07-09 18:26                                       ` Alan Mackenzie
2019-07-09 18:47                                         ` Eli Zaretskii
2019-07-09 18:53                                         ` João Távora
2019-07-10 10:32                                           ` Alan Mackenzie
2019-07-10 10:40                                             ` Lars Ingebrigtsen
2019-07-10 12:24                                               ` João Távora
2019-07-10 14:14                                                 ` Clément Pit-Claudel
2019-07-10 16:07                                                   ` João Távora
2019-07-11 15:14                                                 ` Lars Ingebrigtsen
2019-07-11 15:43                                                   ` João Távora
2019-07-11 15:51                                                     ` Lars Ingebrigtsen
2019-07-11 16:13                                                       ` João Távora
2019-07-12 15:58                                                         ` Lars Ingebrigtsen
2019-07-12 18:47                                                           ` João Távora
2019-07-13  0:08                                                             ` Lars Ingebrigtsen
2019-07-10 12:10                                             ` João Távora
2019-07-10 14:03                                               ` Alan Mackenzie
2019-07-10 16:05                                                 ` João Távora
2019-07-10 17:56                                                   ` Alan Mackenzie
2019-07-11  0:11                                                     ` Richard Stallman
2019-07-03 16:56             ` Stefan Monnier
2019-07-03 16:58             ` Stefan Monnier
2019-07-04 15:24               ` Alan Mackenzie
2019-07-04 15:52                 ` Stefan Monnier
2019-07-04 16:42                   ` Alan Mackenzie
2019-07-04 20:16                     ` Stefan Monnier
2019-07-04 21:27                     ` João Távora
     [not found] ` <handler.36474.B.156207340818492.ack@debbugs.gnu.org>
2019-07-08  9:36   ` bug#36474: Acknowledgement (Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode) Alan Mackenzie

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

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

  git send-email \
    --in-reply-to='CALDnm53=WN2S5Ehz1Tt3On87ERAW-hNexjqymYsC-meA=5vEAQ@mail.gmail.com' \
    --to=joaotavora@gmail.com \
    --cc=acm@muc.de \
    --cc=emacs-devel@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.