unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: "Clément Pit-Claudel" <cpitclaudel@gmail.com>,
	"Stephen Leake" <stephen_leake@stephe-leake.org>,
	"João Távora" <joaotavora@gmail.com>,
	emacs-devel@gnu.org
Subject: Re: CC Mode and electric-pair "problem".
Date: Sat, 30 Jun 2018 19:03:27 +0000	[thread overview]
Message-ID: <20180630190327.GC6816@ACM> (raw)
In-Reply-To: <jwvsh565rye.fsf-monnier+emacs@gnu.org>

Hello, Stefan.

On Fri, Jun 29, 2018 at 00:11:24 -0400, Stefan Monnier wrote:
> >> > How about this idea: we add a new syntax flag to Emacs, ", which
> >> > terminates any open string, the same way the syntax > terminates any
> >> > open comment.  We could then set this syntax flag on newline.
> > I've been making negative comments about this suggestion of mine over
> > the last day or two.  I now believe, again, that the proposal is sound;

> It's definitely sound.  And I very much agree that it could be cleaner
> than the current code on `master`.  I dislike this solution mainly
> because it requires changes to Emacs's core API, so it bumps against my
> feeling that the need is not clearly documented: you think the new
> behavior is more often beneficial than the old behavior but we have no
> actual data to verify it.

No, what I think is much less nuanced: that the old behaviour is simply
wrong; the new behaviour is likewise correct.  If one were to design an
editor's functionality from scratch, nobody would advocate the old
behaviour - it happened because it needed no implementation effort.

> FWIW, I do not know that the old behavior is more often beneficial
> either, but I'm definitely not convinced that the new behavior is
> often enough more beneficial to justify such changes to syntax-tables.

I am in the middle of writing a trial implementation (code speaks louder
than words).  Thus far, it has already worked in shell-script-mode
(which required a one-line change, this:

    -       ?\n ">#"
    +       ?\n ">#s"

the new `s' flag is how I've constructed it, so far).

> But that's for Eli to judge.

> So let's look at the technical issues:
> You suggest introducing a new syntax-table thingy similar to > but for
> strings.  Let's call it ]

As I noted above, I have implemented it as another flag, `s'.

> - This implies we'll need a new C-level function `back_string` to jump
>   backward over such a ]-terminated string, corresponding to
>   back_comment.

Yes.

>  `back_comment` has proved to be rather nasty, so while
>   we can learn from it, part of what we learn is that jumping backward
>   over such things is much easier ....

much less easy.  :-)

>   .... than jumping forward, so this
>   innocuous ] will be more costly than might meet the eye.

It requires the new function, which at the moment seems somewhat less
complicated than back_comment, and this requires to be called from
scan_lists.

> - In CC-mode, \n already has syntax > so it can't also have syntax ]
>   How do you intend to deal with that: will you mark those few \n that
>   terminate strings with syntax-table text-properties?

This is simple with the flag `s'.  NL would thus have end-comment syntax
_and_ the `s' flag.  In scan_lists, back_comment will be tried before
what I'm calling `back_maybe_string', since being a comment ender must have
precedence over being a string terminator.

>   If so, what's the benefit over using string-fences?

String-fence stopped the 'chomp facility of electric-pair-mode working
properly (for the currently accepted value of "properly").

> - Another approach would be to make it possible to mark \n as both ] and
>   > at the same time, which would make the CC-mode feature much cleaner
>   (no need to muck with syntax-table text-properties) but the cost of
>   yet more complexity in the syntax.c code.

That's what I'm doing with `s'.  The extra complexity in syntax.c
doesn't seem all that bad at the moment.  back_maybe_string is currently
137 lines long (including a macro analogous to INC_FROM, and a lossage:
clause modelled on the one in back_comment)), compared with
back_comment's 289 lines.  I'm planning on committing this new code to a
branch in the next few days, then you can judge better whether the new
facility is worth it.

[ .... ]

> > My suggestion has the strong advantage that it will benefit Emacs as a
> > whole, and there won't need to be separate implementations in CC Mode,
> > Python Mode, Ada Mode, .....  The need for a multilinne string to have
> > escaped NLs between its lines is actually a common pattern in the
> > languages Emacs handles.  Why can we not handle it in syntax.c?

> Emacs has handled it for the last 30 years or so.  You just want to
> handle it in a different way.  I agree that Emacs's core should ideally
> make it easy for a major mode to choose this "different way".

> But the way I see it, your suggestion is just adding one more wart to
> syntax-tables whereas we should instead work on "syntax-tables NG".

> IOW, I think that we should introduce a brand new replacement for
> syntax-tables (tho I don't really know what it should look like,
> otherwise I'd have coded it up already); something much more powerful
> and generic (probably based on a mix of a DFA at one level and some kind
> of push-down automata on top of it), and such a thing could/should
> easily accommodate such a feature without even needing any
> ad-hoc support.

"S-T-NG" may be fine for Emacs 28 or 29, but the syntax table is what we
have, and what we must work with in the short term.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2018-06-30 19:03 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22  7:42 [Emacs-diffs] master bb591f139f: Enhance CC Mode's fontification, etc., of unterminated strings Tino Calancha
2018-05-22 17:40 ` Alan Mackenzie
2018-05-22 19:21   ` João Távora
2018-05-22 19:34     ` Eli Zaretskii
2018-05-22 20:25       ` João Távora
2018-05-22 22:17         ` João Távora
2018-05-23 14:52           ` Eli Zaretskii
2018-05-23 20:46     ` Alan Mackenzie
2018-05-23 21:12       ` João Távora
2018-05-23 23:21     ` Michael Welsh Duggan
2018-05-31 12:37 ` CC Mode and electric-pair "problem". (Was: ... master bb591f139f: Enhance CC Mode's fontification, etc., of unterminated strings.) Alan Mackenzie
2018-05-31 16:07   ` CC Mode and electric-pair "problem" João Távora
2018-05-31 17:28     ` Alan Mackenzie
2018-05-31 18:37       ` João Távora
2018-06-02 13:02         ` Alan Mackenzie
2018-06-03  3:00           ` João Távora
2018-06-17 16:58   ` Glenn Morris
2018-06-17 20:13     ` Alan Mackenzie
2018-06-17 21:07       ` Stefan Monnier
2018-06-17 21:27       ` João Távora
2018-06-18 10:36         ` Alan Mackenzie
2018-06-18 13:24           ` João Távora
2018-06-18 15:18             ` Eli Zaretskii
2018-06-18 15:37               ` João Távora
2018-06-18 16:46                 ` Eli Zaretskii
2018-06-18 17:21                   ` Eli Zaretskii
2018-06-18 23:49                   ` João Távora
2018-06-19  2:37                     ` Eli Zaretskii
2018-06-19  8:13                       ` João Távora
2018-06-19 16:59                         ` Eli Zaretskii
2018-06-19 19:40                           ` João Távora
2018-06-18 20:24                 ` Glenn Morris
2018-06-19  2:03                   ` João Távora
2018-06-18 15:42             ` Alan Mackenzie
2018-06-18 17:01               ` João Távora
2018-06-18 18:07                 ` Yuri Khan
2018-06-18 22:52                   ` João Távora
2018-06-18 18:08                 ` Alan Mackenzie
2018-06-18 23:43                   ` João Távora
2018-06-19  1:35                     ` João Távora
2018-06-19  1:48                   ` Stefan Monnier
2018-06-19  3:52                     ` Clément Pit-Claudel
2018-06-19  6:38                       ` Stefan Monnier
2018-06-20 13:48                         ` Clément Pit-Claudel
2018-06-26 16:08                     ` Fontifying unterminated strings [was: CC Mode and electric-pair "problem".] Alan Mackenzie
2018-06-26 20:02                       ` João Távora
2018-06-28 23:56                       ` Stefan Monnier
2018-06-29  0:43                         ` Stefan Monnier
2018-06-18 22:41                 ` CC Mode and electric-pair "problem" Stephen Leake
2018-06-19  0:02                   ` João Távora
2018-06-19  3:15                   ` Clément Pit-Claudel
2018-06-19  8:16                     ` João Távora
2018-06-19  5:02                 ` Alan Mackenzie
2018-06-20 14:16                   ` Stefan Monnier
2018-06-26 18:23                     ` Alan Mackenzie
2018-06-27 13:37                       ` João Távora
2018-06-29  3:42                       ` Stefan Monnier
2018-06-30 18:09                         ` Alan Mackenzie
2018-07-01  3:37                           ` Stefan Monnier
2018-07-01 15:24                             ` Eli Zaretskii
2018-07-06 21:58                             ` Stephen Leake
2018-07-01 15:57                           ` Paul Eggert
2018-06-27 18:27                     ` Alan Mackenzie
2018-06-29  4:11                       ` Stefan Monnier
2018-06-30 19:03                         ` Alan Mackenzie [this message]
2018-06-30 19:29                           ` Eli Zaretskii
2018-06-30 20:14                             ` Alan Mackenzie
2018-07-01  3:50                               ` Stefan Monnier
2018-07-01  9:58                                 ` Alan Mackenzie
2018-07-01 11:22                               ` João Távora
2018-07-01 15:25                                 ` Eli Zaretskii
2018-07-01 15:22                               ` Eli Zaretskii
2018-07-01 16:38                                 ` scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".] Alan Mackenzie
2018-07-08  8:29                                   ` Stephen Leake
2018-07-15  9:00                                     ` Stephen Leake
2018-07-15 15:13                                       ` Eli Zaretskii
2018-07-15 18:45                                         ` Alan Mackenzie
2018-07-16  2:23                                           ` Indentation of ?: in C-mode (was: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".]) Stefan Monnier
2018-07-16 14:18                                             ` Eli Zaretskii
2018-07-16 15:54                                               ` Indentation of ?: in C-mode Stefan Monnier
2018-07-15 16:56                                       ` scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".] Alan Mackenzie
2018-07-17  3:41                                         ` Stephen Leake
2018-07-01  4:02                           ` CC Mode and electric-pair "problem" Stefan Monnier
2018-07-01 10:58                             ` Alan Mackenzie
2018-07-01 11:46                               ` João Távora
2018-07-01 16:13                               ` Stefan Monnier
2018-07-01 18:18                                 ` Alan Mackenzie
2018-07-01 23:16                                   ` Stefan Monnier
2018-07-02 19:18                                     ` Alan Mackenzie
2018-07-03  2:10                                       ` Stefan Monnier
2018-06-26 18:52                   ` Alan Mackenzie
2018-06-26 19:45                     ` João Távora
2018-06-26 20:09                       ` 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

  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=20180630190327.GC6816@ACM \
    --to=acm@muc.de \
    --cc=cpitclaudel@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    --cc=monnier@IRO.UMontreal.CA \
    --cc=stephen_leake@stephe-leake.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).