[Top][All Lists]

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

Re: cc-mode: Make all parameters introduced in Emacs 26 optional

From: Stefan Monnier
Subject: Re: cc-mode: Make all parameters introduced in Emacs 26 optional
Date: Sat, 30 Mar 2019 16:17:25 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>>     (modify-syntax-entry ?' "\"" st)
> Maybe, but that doesn't give you the facilities that CC Mode offers,
> namely that the delimiters of invalid constructs (such as unterminated
> strings, or invalid character constants) get fontified with warning face.

... or quotes-in-numbers, indeed.

> One question which has just occurred to me is why am I doing this in CC
> Mode rather than the syntax and font-lock functionality handling it
> directly?  Languages where strings don't extend over unescaped newlines
> aren't exactly a rarity.

I think doing it in the syntax part is not necessary: the design of the
syntax is made simpler and more efficient by assuming that the behavior
on invalid code is largely irrelevant.  And efficiency is important
there when we need to parse-partial-sexp a large buffer.

But providing support for highlighting such errors in font-lock
(e.g. within font-lock-fontify-syntactically-region) would make a lot of
sense, yes.

Or maybe the simplest would be to provide
a `font-lock-flag-multiline-strings` function that modes can add to

>> But the above sounds surprisingly complex&scary,
> It only looks like that because I've spelled it out so laboriously.  There
> are two hook variables, each of which needs one function and the lack of
> another.

After re-reading the description I wonder if it couldn't be made simpler
by making those hook functions check c-single-quotes-quote-strings
instead (or have separate code in the cc-mode setup which adds/removes
those hooks as needed based on c-single-quotes-quote-strings,
essentially replacing the docstring text with executable code)?

Also I still wonder why c-has-quoted-numbers is incompatible with
c-single-quotes-quote-strings.  I guess c-has-quoted-numbers only
exists in C++, so in practice no language needs both features, but
I can't see any reason why the CC-mode code wouldn't work just as
well when both features are set.  While both have to do with ' they seem
fundamentally orthogonal.


reply via email to

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