[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CC Mode and electric-pair "problem".

From: Stefan Monnier
Subject: Re: CC Mode and electric-pair "problem".
Date: Fri, 29 Jun 2018 00:11:24 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>> > 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.  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

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 ]
- This implies we'll need a new C-level function `back_string` to jump
  backward over such a ]-terminated string, corresponding to
  back_comment.  `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 than jumping forward, so this
  innocuous ] will be more costly than might meet the eye.
- 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?
  If so, what's the benefit over using string-fences?
- 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.

> would need to find the start of bar.  In other words, we would have to
> pair off quotes from the beginning of the line we were scanning
> backwards over.  There may well be difficulties in a NL potentially
> acting as the terminator of both a string and a comment.  I think these
> are the sorts of complexity you're wary of.


> 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]