emacs-devel
[Top][All Lists]
Advanced

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

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


From: Alan Mackenzie
Subject: Re: CC Mode and electric-pair "problem".
Date: Wed, 27 Jun 2018 18:27:17 +0000
User-agent: Mutt/1.9.4 (2018-02-28)

Hello, yet again, Stefan.

On Wed, Jun 20, 2018 at 10:16:05 -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 would allow the desired fontification (an unterminated string being
fontified only up to the next unescaped NL) easily, without interfering
with the 'chomp facility in electric-pair-mode.

> To me this looks like adding a hack to patch over another.

> I don't think the new behavior of unclosed strings in CC-mode is worse
> than the old one, but I don't think it's really better either: it's just
> different (in some cases it's better in others it's worse).

This new fontification in CC Mode is much better.  When the terminating
" is missing, it no longer fontifies spuriously an unbounded piece of
the buffer as a string.  Clëment and Stephen Leake have responded
positively to this possibility.  I think we should enhance Emacs such
that it is easy to fontify in this new way.

> So the problem I see with it is that it brings complexity in the code
> with no real improvement in terms of behavior.  The bad-interaction with
> electric-pair shows that this complexity has a real immediate cost.
> The suggestion above suggests that this complexity may bring in yet
> more complexity.

The desired facility _is_ complicated.  I am not fond of the code in CC
Mode which implements it.  The question is, where do we put this
complexity?  With my suggestion, it would be confined mainly to the
scanning routines in syntax.c rather than being spread (and duplicated)
amongst several major modes.

Adapting the forward scanning functionality would be straightforward.
Things like (scan-sexps POS -1) would indeed become more difficult.  For
example, starting at BONL, (scan-sexps BONL -1) in

    "foo bar

would need to find the ", but the same in

    "foo"bar

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.

font-lock-fontify-syntactically-region could then be amended
straightforwardly to apply warning-face to the opening unbalanced "
(controlled, of course, by a customisation option).

> Me not happy.

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?

[ .... ]

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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